-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
mpd_playlist_fix
executable file
·61 lines (50 loc) · 1.18 KB
/
mpd_playlist_fix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
# mpd_playlist_fix
# abstract: remove invalid entries from m3u playlists
use Audio::MPD;
use Tie::File;
use File::LsColor qw(ls_color);
use Term::ExtendedColor qw(:attributes);
my $mpd = Audio::MPD->new(
host => $ENV{MPD_HOST},
port => $ENV{MPD_PORT},
);
my $base_dir = "/mnt/Music_1";
my $playlist_dir = "$base_dir/Playlists";
my @playlists = map {
$_ = "$playlist_dir/$_.m3u"
} $mpd->collection->all_playlists;
edit_playlist( @playlists );
sub edit_playlist {
my @list = @_;
for my $l(@list) {
tie(@content, 'Tie::File', $l) or die("Cant tie: $!\n");
my $i = 0;
for my $file(@content) {
next if $file !~ /[\w]/;
if(!-f "$base_dir/$file") {
printf("%25s:%s %s\n",
basename($l),
fg(40, bold(sprintf("%02d", $.))),
ls_color(basename($file))
);
print "Remove? [y/N] ";
chomp(my $answer = <STDIN>);
if(lc($answer) ne 'y') {
next;
}
else {
undef $content[$i];
}
}
$i++;
}
}
@content = map { s/^\s+$//g } @content;
untie(@content);
}
sub basename {
my $file = shift;
$file =~ s{.*/(.+)$}{$1};
return $file;
}