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 = <STDIN>; $a =~ /(\d\d) - (.*).mp3/; print $2;'`; id3 -t "$TRACKNAME" "$f"; done

Creative Commons License

4 Responses to “Fast ID3 tagging”

  1. vrypan says:

    Any chance you write a script that will extract the ID3 tags of an mp3 (podcast file :-) and creates the content for bucket3 to parse and automatically create a new post?

    Just asking ;-)

  2. cosmix says:

    You mean like an ‘mp3 handler’? You could use pytagger or another lib to do this extremely fast. What I’m not so sure about (i.e. I haven’t tested) is Unicode support and proper support for ID3v2.x (although this is claimed to be there).

  3. saperduper says:

    Who cares for the grander scheme of things, when all of my mp3 files are properly tagged?

    Seriously, these snippets could be motivational for some users, who haven’t had the chance to discover the power of the console. They are provided with slick workarounds of everyday problems and this might be the push they need to start exploring Perl/shell scripts or even switch their OS.

    Anyway, i enjoy reading about tiny scripts that simply “get things done” and i suggest you keep ’em coming.

    cheers mate!

  4. harry says:

    saperduper +1

    Nice one-liner cosmix

Have your say.

Write in the language of the post. Comments are meant to encourage on-topic discussion. For general comments, observations, complaints (e.g. about the site), you can use the form found in the Contact page. Make sure you've read the Terms of Use before commenting.

Comments Feed for this post Comments Feed for this entry.

Linode. Affordable, Fast, SSD VPS