# uses http://home.wanadoo.nl/squell/id3.html use warnings; use strict; use MP3::Info; use File::Find; my $dir = '.'; my $info; my %tags; my $file; finddepth(\&tagit, $dir); sub tagit { if (-f) { if ($File::Find::name =~ /\.mp3$/) { $info = get_mp3tag($_); if (!defined $_{"TITLE"}) { buildhash($File::Find::name); writehash($file); } } } } sub buildhash { my $path = shift; $path = substr($path, 2, length($path) - 2); # strip leading ./ $file = substr($path, rindex($path, '/') + 1, length $path); my $folder = substr($path, index($path, '/') + 1, rindex($path, '/') - 6); print $folder."\n"; ($tags{"GENRE"}) = substr($path, 0, index($path, '/')); ($tags{"ARTIST"}) = $folder =~ /^(.*?) - .*?/; ($tags{"ALBUM"}) = $folder =~ /^.*? - (.*?)( \(|$)/; ($tags{"TRACK"}) = $file =~ /^(\d\d).*/; ($tags{"YEAR"}) = $folder =~ /\((\d\d\d\d)\)/; ($tags{"TITLE"}) = $file =~ /\d\d(.*)\.mp3/; ($tags{"TITLE"}) = $tags{"TITLE"} =~ /([b..Z].*)/; } sub writehash { my $command; $command .= "C:/id3.exe -2 -1 -v -M"; if (defined $tags{"GENRE"}) { $command .= " -g \"".$tags{"GENRE"}."\""; } if (defined $tags{"ARTIST"}) { $command .= " -a \"".$tags{"ARTIST"}."\""; } if (defined $tags{"ALBUM"}) { $command .= " -l \"".$tags{"ALBUM"}."\""; } if (defined $tags{"TRACK"}) { $command .= " -n \"".$tags{"TRACK"}."\""; } if (defined $tags{"TITLE"}) { $tags{"TITLE"} = join(" ", map ucfirst(lc($_)), split(/\s+/, $tags{"TITLE"})); $command .= " -t \"".$tags{"TITLE"}."\""; } if (defined $tags{"YEAR"}) { $command .= " -y \"".$tags{"YEAR"}."\""; } $command .= " \"$file\""; #print "\n$command\n"; system($command); #system("C:/id3.exe -d -M -v -2 \"$file\""); }