I have all of my CD collection stored as MP3 files. As part of this system, I have several Perl scripts which rely upon the MP3 tag in order to perform certain processes. As I was testing these scripts, I discovered that (for whatever reason) many of the MP3 files did not contain MP3 tag information.
The following script creates a file of all MP3 files which don't have MP3 tag information. This file can then be passed to another script for further processing.
The script is quick and dirty, is of obvious limited usefulness and could probably be coded more cleanly. However, it works and it works well. I'm just posting it here (1) because once again, Perl has the solution to my problem, and (2) in the hopes that others may find it useful.
Comments and improvements are most welcome.
#!/usr/bin/perl
use strict;
# only these fields need to be changed
@ARGV = qw(/music/mp3/); # where MP3 files are located
my $outfile = "$ENV{HOME}/mp3/NoTag"; # where to write the output
# nothing below here needs to be changed
open (MP3, "> $outfile") || die "can't open MP3: $!";
use File::Find;
use MPEG::MP3Info;
&File::Find::find(\&check, @ARGV);
exit;
sub check {
if ($File::Find::name !~ /\.mp3$/) {
return;
}
my $tag = get_mp3tag($File::Find::name);
if (!($tag)) { # if no id tag, print
print MP3 "$File::Find::name\n";
}
}
If things get any worse, I'll have to ask you to stop helping me.