Saturday, November 14, 2009

ID3 tags, revised

The program I put up last post works - sort of. There are a couple problems with it. First, it only handles three specific tags. Second, it doesn't actually use the information about the tag size that's in the tag itself. Third, it only works for version 2.2 tags. I've fixed all those issues in this. The new code is here. I'll go over a couple things in there that I haven't mentioned before.

charToInteger x = (toInteger . ord) x

(Line 91) ord lives in Data.Char; it converts a character to its numeric equivalent (i.e. ord 'A' is 65). toInteger converts values of Integral types to Integer values.

let . . . in . . .

(Line 114, among others) let essentially binds a value to a name only for the duration of the statement following "in." (Note that if you're using GHCI, let is used to bind a value for the duration of the session.)

Out program now mostly works. We can run it on a file with version 2.3 ID3 tags:
Composer: ??
Title: ??Meet The Elements
Copyright message: ??(C) 2009 Disney
Content type: ??Children's Music
Artist: ??They Might Be Giants
Conductor/Performer refinement: ??
Album title: ??Here Comes Science (Amazon MP3 Exclusive Version)
Language code: eng
Content descriptor: ?
Contents: ??Amazon.com Song ID: 212903562
Track number: ??2/20
Accompanied by: ??They Might Be Giants
Part of a set: ??1/1
Year: ??2009

The information is all correct; this file contains "Meet The Elements" from the newest They Might Be Giants album, Here Comes Science. (I assume it also works on version 2.4 tags, but I don't have any conveniently-located files that have them.)
Now, notice those ??'s? And remember how I said that this program mostly works? The text tags in this file are in Unicode. (I believe it's UTF-16 big-endian, to be specific) Right now, the program disregards the encoding bytes, and assumes everything uses ISO-8859-1. Next step: fixing this.

No comments:

Post a Comment