From: Don Armstrong Date: Wed, 5 Sep 2012 01:12:31 +0000 (+0000) Subject: add mpd_remove_duplicates X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=69b72edc931bded7d2a8af5361bb551dce5c1568;p=bin.git add mpd_remove_duplicates --- diff --git a/mpd_remove_duplicates b/mpd_remove_duplicates new file mode 100755 index 0000000..2574faf --- /dev/null +++ b/mpd_remove_duplicates @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +use warnings; +use strict; + + +use Audio::MPD; + +my $mpd = Audio::MPD->new; + +my $pl = $mpd->playlist; + +my @items = $pl->as_items; + +my %items_to_delete; +my %files; +for my $item (@items) { + my ($name,$type) = $item->file =~ m/(.+)\.([^\.]+)/; + if (exists $files{$name}{$type}) { + $items_to_delete{$item->id} = 1; + next; + } + $files{$name}{$type} = $item->id; + if (exists $files{$name}{flac}) { + $items_to_delete{$_} = 1 foreach values %{$files{$name}}; + delete $items_to_delete{$files{$name}{flac}} + } elsif (exists $files{$name}{ogg}) { + $items_to_delete{$_} = 1 foreach values %{$files{$name}}; + delete $items_to_delete{$files{$name}{ogg}} + } +} + +$pl->deleteid(keys %items_to_delete);