Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

acme (189)

acme
  (email not shown publicly)
http://www.astray.com/

Leon Brocard (aka acme) is an orange-loving Perl eurohacker with many varied contributions to the Perl community, including the GraphViz module on the CPAN. YAPC::Europe was all his fault. He is still looking for a Perl Monger group he can start which begins with the letter 'D'.

Journal of acme (189)

Wednesday January 29, 2003
06:21 AM

MP3::ID3Lib

[ #10261 ]
Blech has been working on categorising all his MP3s, and needed to be able to read and write ID3v2 tags. Now, MP3::Info is pretty cool, but doesn't support writing of tags. Blech pointed me at the ID3Lib library, "an open-source, cross-platform software development library for reading, writing, and manipulating ID3v1 and ID3v2 tags", which seems to be what many MP3 tools use. And I foolishly agreed to try and code up a Perl module for him.

What is all this ID3 nonsense, you ask? Well it's be easy to explain if the ID3.org website were up more often. ID3 tags are small pieces of information stored inside the MP3 file. They can contain bits of metadata about the MP3, such as album name, song name, artist, original artist, genre, composer, year of release, additional comment fields, and many more. Unfortunately, there have been many versions of the ID3 spec and it has slowly been getting more and more complicated. Oh, and the tags are typed. And may have other fields than simply "value". And tags have been renamed in newer versions of the spec for no real reason other than to confuse me. A simple key -> value frame at the end of the MP3 file would have been so much simpler, but unfortunately we can't change the world overnight.

Anyway, ID3Lib reads and writes these tags. The actual library is in C++ but there is a cut-down C interface which I picked as I know no C. After refreshing my XS and typemap knowledge, it all pretty much fell into place. One strange thing was having to use g++ to compile the XS. Is there a more-portable way to find a C++ compiler than:

# In Makefile.PL
'CC' => 'g++',
'LD' => 'g++',

The current docs and API are a little lacking and there's a small memory leak, but it works! It's up on the CPAN, phew.

And thanks to Pudge for letting me use his test MP3s...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • MP3::Info is pretty cool, but doesn't support writing of tags.

    I could have sworn that I've been using MP3::Info to write tags for months. The docs mention a set_mp3tag function.

    • Oooops, I should have said "but doesn't support writing of ID3v2 tags".
    • As acme notes, MP3::Info doesn't currently support writing id3v2 tags. However, he doesn't explain why this is so important.

      Firstly, id3v1 has length limits on all the fields it supports, usually about 40 or so characters. Secondly, id3v1 only supports six (I think) basic tags.

      As I like to keep the file names of my mp3s short (so I can still see them with the Mac OS 9 Finder, amongst other reasons), that means the id3 tags have to keep all the metadata about the mp3s, so id3v1 just doesn't cut it. (Not en
      • It is 30 characters per field for ID3v1, for artist, album, title, and comment. If you use ID3v1.1 (which has a track number field), comment is then limited to 28. Year is 4.

        I have over a dozen MP3::Info patches to apply; when Apple sends me my new PowerBook, I am going to work more on them. One of them has to do with writing ID3v2 tags. I've not tried it yet, but someone wrote MP3::Info::set_mp3v2tag [cpan.org], and has given me permission to integrate it into MP3::Info. Have you tried this module? I've not ye
        • I have tried set_mp3v2tag, yes. It works fairly well for the core fields, and is a pretty good starting point.

          My one complaint is that it doesn't set comments correctly, because id3v2 allows multiple comment frames, distinguished by the language and description. I have a (three-line) local patch that uses 'eng' as the default language, which is probably acceptable as a convenience.
  • Yes, id3lib is fantastic. It was the only thing I could find to convert the tags on my old RealJukebox-ripped mp3s into a format that iTunes could deal with. iTunes' conversion of tags doesn't do anything, as far as I could tell.

    Why do you need a Perl interface? I've been doing a ton of things like this: % ls -1 "His Dark"* | perl -nle '/(.*) - (\d+) - (.*)/; system("id3tag", "-aBBC", "-A$1", "-s$3", "-t$2", "-T3", $_)' (for those without id3lib, that takes His Dark Materials - 1 - The Amber Spygla