Fast ID3 tagging

This is solely for my friend saper who was recently telling me how much he loves it when people post snippets of code that they come up with during their everyday lives, even if they are relatively pointless in the grander scheme of things. Well, today I was listening to a few old mp3 files while coding more important stuff and realised that some had no id3 tags, which was a good excuse to put good ol’ PERL and some shell magic to some use to tag them all, fast. Here’s the two-minute script for tagging files based on the filename (note the ‘[trackno] – [title].mp3’ regex). I ran the script twice, once for the trackname and once for the track number (not shown below, is trivial and left as an exercise for the reader). Hope this is useful to someone, although I guess it mostly serves as proof as to how much you can do with one line of PERL/shell scripting magic. Enjoy =)

ls *.mp3 | while read f; do TRACKNAME=`echo "$f" | perl -e '$a = ; $a =~ /(\d\d) - (.*).mp3/; print $2;'`; id3 -t "$TRACKNAME" "$f"; done