10 Oct 2006

itunes persistent ids and 64 bit integers

itunes 6.0.x introduced a concept called "persistent id". this is a reference you could use to identify playlists and tracks and is persistent across the life of your music library.

i had an initial attempt to get the support working for the EyeTunes.framework but my first attempt at doing this failed miserably. tonight, i took some time to look at this again and i've finally fixed it! EyeTunes.framework can now both get the persistent id and also use it to grab playlists and tracks.

the problem with my initial implementation was simply because i thought AppleEvent's double integer corresponded to their long() type. however, there is in 64 bit integer type some apple engineers decided, hey that double float over there is 64 bit, why not use that as storage for a 64 bit integer. and so, if you go into apple script editor and type this:

tell application "iTunes"
persistent id of selection
end tell

that will actually output a floating point number! because when apple script editor sees a 64 bit number, it thinks it is a float. the reverse is even worse, you cannot input a 64 bit number through apple script editor.

anyway, that was part of the problem because i had previously relied on script editor working and reverse engineering the gizmo strings via gdb. however, that didn't work so i guessed what it was, and it turned out wrong.

turns out, after poking at aeve, Bob Ippolito's python apple event implementation that long integers can be alternatively represented by typeSInt64, and thus, i've made the appropriate fixes to EyeTunes.framework and now you have persistent id fun. most importantly, they check out against the ID that is in the "iTunes Music Library.xml" file.

so why does this matter? apparently, the new album art that you can get from itunes is stored locally on your disk with some reference to the persistent id in your music database. and according to some people (i have not verified this), album art you download from itunes is not inserted into your MP3s but stored separately.

anyway, the new code is in the current EyeTunes SVN.

You can reply to me about this on Twitter: