Using Perl to process MP3s
I recently got a Squeezebox Duet and have been getting my large MP3 collection into shape. It turns out that SqueezeCenter prefers different tags than Amarok. So getting my music to appear the same in both places has been quite a task. What I figured out is that I had to remove extra junk from the files, convert any tags to ID3v2.4, and then for good measure I strip the ID3v1 tags.
I found three linux programs that do this well, mp3check, eyeD3, and id3convert (part of the id3lib project), but running them manually and remembering which one does what was too hard… So I wrote a Perl script to simplify the process. It takes paths as command line arguments, and will process the MP3s the way I like ‘em. It even sets the permissions correctly!
#!/usr/bin/perl -w
use strict;
while ( @ARGV ) {
my $path = shift ( @ARGV );
# cut the junk
system ( "find $path -name *.mp3 -exec mp3check --cut-junk-end {} \\;" );
# convert the tags to ID3v2.4
system ( "find $path -name *.mp3 -exec eyeD3 --to-v2.4 {} \\;" );
# strip ID3v1 tags, just in case
system ( "find $path -name *.mp3 -exec id3convert -s1wn {} \\;" );
# set permissions correctly
system ( "chmod -R 755 $path" );
}
