The tale of two iTunes APIs (one of these things is not like the other)
I find this somewhat amusing but mostly exasperating:
To save album artwork with the Apple com library on Windows you do the following:
artwork = self.GetCurrentTrackArtwork()
if artwork and len( artwork ):
artwork[0].SaveArtworkToFile("/PATH/TO/THE/FILE" )
Looks pretty simple, nice and clean, no problems, but take a look at the AppleScript library on OS X:
artwork = self.GetCurrentTrackArtwork()
data = artwork.data
# PNG HEADER ? P N G
substr = [ 0x89, 0x50, 0x4E, 0x47 ]
idx = self.FindSubstring( data, substr )
graphic = None
if idx:
graphic = data[idx:-1 ]
fout = file( ARTWORK_IMAGE, "wb" )
fout.write( graphic )
fout.close()
return
# JPEG HEADER J F I F
substr = [ 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, ]
idx = self.FindSubstring( data, substr )
if idx:
graphic = data[idx:-1 ]
fout = file( ARTWORK_IMAGE, "wb" )
fout.write( graphic )
fout.close()
To say there was a little hoop jumping going on here is an understatement, I also had to write the substring method to
search for the ordinal values, and if Apple adds a new graphic format for the cover art, my OS X version breaks and I have to
release a fix, not exactly flexible or easy to use, but maybe that’s the point. Tsk, tsk, tsk…