Thursday, June 11, 2009

A look at the iTunes XML and playlist formats

The playlist converter basically grabs the playlists in iTunes and converts them into a different format. Before looking at the code, here is a short description of the relevant formats.

iTunes XML

iTunes stores the “meta-information” about the music, playlists etc. that you can use and set up in iTunes in an XML file called “iTunes Music Library.xml” which is usually stored in the iTunes music folder (usually My Documents\My Music\iTunes).

There is a couple of web documents that describe the format. I have used an article by Niel Bornstein called “Hacking iTunes”. Some examples here are taken from this article.

There are three main sections in the file:

  1. some meta info (such as general location infos, version etc.)
  2. tracks info (a large dictionary of track information)
  3. playlists info (a large dictionary of playlist information)
Tracks

For each track, there is number of key – value pairs. ‘Key’ can be Track ID, Name, Artist and Location, whereas value can be a number or string which denotes the key’s value, e.g.

 <key>Track ID</key><integer>839</integer>
<key>Name</key><string>Sweet Georgia Brown</string>
<key>Artist</key><string>Count Basie & His Orchestra</string>
<key>Composer</key><string>Bernie/Pinkard/Casey</string>
<key>Location</key><string>file://localhost/Users/niel/Music/iTunes/iTunes%20Music/Count%20Basie%20&%20His%20Orchestra/Prime%20Time/03%20Sweet%20Georgia%20Brown.m4p</string>
Playlists
Each playlist also has some meta information (such as name etc., lines 2 to 4) and an array with the TrackIDs of the tracks that make up the playlist (lines 7 to 14):
<dict>
<key>Name</key><string>Funky</string>
<key>Playlist ID</key><integer>6652</integer>
<key>Playlist Persistent ID</key><string>88CED99A2F698F3C</string>
<key>All Items</key><true/>
<key>Playlist Items</key>
<array>
<dict>
<key>Track ID</key><integer>837</integer>
</dict>
<dict>
<key>Track ID</key><integer>754</integer>
</dict>
</array>
</dict>
This playlist (called “Funky”) contains two tracks (with the IDs 837 and 754). Information about these tracks can be obtained from the tracks section using the IDs. As this is a “plain” XML file, it can be queried using LinQ To XML.

M3U playlist

The M3U playlist format is very simple, it is just a list of the files to be played, each title in its own line:
\\Marvin\musik\Download\Run\01 01 Mornin'.mp3
\\Marvin\musik\Download\Run\13 08 Man Of La Mancha (I, Don Quixote).mp3
\\Marvin\musik\Download\Bike\01 01 Child's Anthem.mp3
This playlist contains three titles, each denoted by the location of their MP3 files. Additional information (Artist, Title, Album etc.) can only be obtained from the meta-information stored in the MP3 files. The file is a plain text file – as I only have to write to this file, I’m just using a simple TextStream to write to. If the format was a bit more involved (say another, maybe differently formatted XML file), I could have used LinQToXML again, but it would be overkill for writing M3U files.

Main | Next

No comments:

Post a Comment