Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 79 lines (63 sloc) 2.48 KB
#!/usr/bin/env perl
use autodie qw(:all);
use Modern::Perl;
use Data::Dump 'dump';
open my $dirs, "find ~/Podcasts -mindepth 2 -type d |";
while (my $dir = <$dirs>) {
chomp $dir;
chomp(my @albums = split /^/, qx[ find "$dir" -type f -name '*mp3' -exec id3info {} \\; | grep TALB | perl -pe 's/.*?: //' ]);
chomp(my @artists = split /^/, qx[ find "$dir" -type f -name '*mp3' -exec id3info {} \\; | grep TPE1 | perl -pe 's/.*?: //' ]);
my (%artists, %albums);
$artists{$_}++ for @artists;
$albums{$_}++ for @albums;
my ($artist) = sort { $artists{$b} <=> $artists{$a} } keys %artists;
my ($album) = sort { $albums{$b} <=> $albums{$a} } keys %albums;
next unless $artist and $album;
my @files = glob qq[$dir/*.mp3];
say dump {
dir => $dir,
artists => $artist,
albums => $album,
files => scalar(@files),
};
for my $file (@files) {
chomp(my $a = qx[id3info "$file" | grep TPE1 | perl -pe 's/.*?: //']);
chomp(my $l = qx[id3info "$file" | grep TALB | perl -pe 's/.*?: //']);
if ($a ne $artist) {
#say "Setting ARTIST='$artist', was ARTIST='$a' on $file";
my $cmd = qq[eyeD3 --to-v2.3 "$file" && eyeD3 --artist="$album" "$file"];
say $cmd;
system $cmd;
}
if ($l ne $album) {
#say "Setting ALBUM='$album', was ALBUM='$l' on $file";
my $cmd = qq[eyeD3 --to-v2.3 "$file" && eyeD3 --album="$album" "$file"];
say $cmd;
eval {
system $cmd;
};
}
# Set track numbers
if ($dir =~ /The_Skeptics_Guide_to_the_Universe$/) {
if (my ($track) = $file =~ /_(\d+)_-/) {
chomp(my $t_str = qx[id3info "$file" | grep TRCK | perl -pe 's/.*?: //']);
my ($t, $tt) = split m[/], $t_str;
$t //= '';
$tt //= '';
# Strip leading zeros
s/^0+// for $t, $tt;
my $total_tracks = @files;
if ($t ne $track) {
my $cmd = qq[eyeD3 --to-v2.3 "$file" && eyeD3 --track="$track" "$file"];
say $cmd;
system $cmd;
}
if ($tt ne $total_tracks) {
my $cmd = qq[eyeD3 --to-v2.3 "$file" && eyeD3 --track-total="$total_tracks" "$file"];
say $cmd;
system $cmd;
}
}
}
}
}