Slashdot Mirror


Efficiently Reading ID3v2 Tags Over HTTP?

Paul Crowley asks: "Given an HTTP URL for an MP3 file, what's the best way to read its ID3 tags on a GNU/Linux system? It shouldn't be necessary to fetch the whole file: HTTP byteranges should make it possible to fetch only the tiny fraction that's needed, for a big saving in network bandwidth. However, existing ID3v2 libraries are designed to read local files. Extending these libraries for this purpose, or implementing a new one, would be a big job. What's the clean solution - is FUSE the best way, or is there a simpler way that doesn't require root privs? Can I do it using the existing id3lib binary?"

7 of 65 comments (clear)

  1. ID3v2 Sucks by DeadSea · · Score: 5, Informative
    As somebody who has tried to write libraries that read ID3v2 tags, I'd have to say I hate them. The standard is clear and well documented, but the chosen format is horrible. It is very hard to write a parser correctly. It would have been so much better to embed an XML document at the front of the MP3 file. Instead they decided to make each field in a special binary format prepended by a length field.

    The number of checks you have to do is phenominal. The biggest worry is buffer overflow where the length given is greater than the actual length of the tag and you read more than is in the file. There are just hundreds of such edge cases. Libraries for ID3v2 are likely to be buggy, crashy, and just no fun.

    1. Re:ID3v2 Sucks by foofboy · · Score: 3, Informative

      I hear you on that. I wrote a python module for id3v2 tags. It reminded me of nothing so much as ASN.1/BER/DER.

      It does, however, support arbitrary character sets and arbitrary binary formats, though. Not sure there's another way to do it. Vorbis-comments are ASCII only, right?

      I look forward to your reply.

    2. Re:ID3v2 Sucks by Fweeky · · Score: 4, Informative

      foobar2000 uses APEv2 tags on MP3's by default; the standard's just as flexible (well, as much as anyone wants anyway), but, well, you just need to compare filesizes for their handlers; an ID3v2 reader/writer I saw was ~150k of code -- the APEv2 one was 15k. They're always at the end, but obviously since fb2k is the only player I'm aware of which supports it the appeal may be limited. You can at least mix them with ID3v1, which should be good enough for portables.

      And before anyone goes off on one because it's non-standard, I'll point out that MP3 has *no* provision for metadata. ID3v1 and 2's are just as arbitary addons as APEv2; they're just older (and lamer, either in big limitations or extreme overcomplication).

      I believe the recommended *standard* way of attaching metadata to an MP3 now is to put it in an MP4 container, which has it's own more sensible format. Again, I'm pretty sure foobar2000 (maybe with some plugin in the Special Installer) can put them in, and I think they should play on anything which knows about MP4. Fully reversable too.

  2. Re:HTTP 499 by eyeball · · Score: 4, Informative
    From the ID3v2 FAQ:
    Q: Where is an ID3v2 tag located in an MP3 file?

    It is most likely located at the beginning of the file. Look for the marker "ID3" in the first 3 bytes of the file.

    If it's not there, it could be at the end of the file (if the tag is ID3v2.4). Look for the marker "3DI" 10 bytes from the end of the file, or 10 bytes before the beginning of an ID3v1 tag.

    That's the problem -- it could be at the end, requiring you to spin through all x bytes (most likely megs) until you get to the end.
    --

    _______
    2B1ASK1
  3. MP3::Info Perl module by extra88 · · Score: 3, Informative

    Look at the MP3::Info Perl module, you might recognize the author's handle. It reads (and writes) tag info. It's used by the "jukebox" module Apache::MP3 (sample site) to generate pages with track info.

    Basically every web jukebox out there does something like this so I'm sure there's plenty of other code available to work from. The mod_perl way is to put SetHandler perl-script then PerlHandler [name of module] in your httpd.conf file so when a URL request falls within that Location or Directory, the perl module handles returning whatever you want it to return.

  4. Re:HTTP 499 by cryptor3 · · Score: 3, Informative
    That's the problem -- it could be at the end, requiring you to spin through all x bytes (most likely megs) until you get to the end.

    Yeah, that could be true, but if it's not within say, the first 100KB, then the smart thing to do is to stop trying to find it and just return an error.

    If it's not at the beginning, you could then use byte ranges to try to fast forward to the end and guess that it will be within the last say, 50 KB of the end.

  5. Vorbis comments UTF-8 by rillian · · Score: 4, Informative

    Vorbis-comments are ASCII only, right?

    No. The field names are ACSII only (actually a printable subset minus '=') but the contents of the fields are specified as UTF-8.

    The intention was you could put arbitrary binary data in there too, but there's no general mechanism for marking it as anything else. So any non-UTF-8 use would be application specific.