Mike Bland

Extracting Album Artwork From iTunes 11

Extracting the album artwork for Jimi Hendrix's "People, Hell & Angels" from iTunes 11, using vim to change the binary ITC file format to JPEG

- Boston
Tags: Jimi, Mac OS X, technical

Happy day! I got the latest Jimi Hendrix album, People, Hell, & Angels, from Amazon today. It’s so new that the online music databases don’t yet have the cover art. To remedy this, my first impulse was to scan the CD cover myself, but my scanner driver decided to freak itself out temporarily. While rebooting my machine, which did in fact remedy the driver issue, I recalled that iTunes does have the artwork already—and it’s a far sight better than what I could expect to scan myself, most likely.

Little did I know I was jumping down another rabbit hole, though thankfully a relatively shallow one. Still, I feel the need to document what I learned during the process as a note-to-self, and to allow for the possibility of sparing others a few precious moments when faced with the same task.

Just because I’m obsessive about archiving, I like to rip my physical CDs—what few I choose to purchase over direct iTunes purchases these days—to the lossless FLAC format using XLD on Mac OS X, even though I still rip them to iTunes in AAC format, so I can use DoubleTwist to sync my iTunes library to my Android phone.1 XLD can embed the cover art in the tracks if it can find it online; otherwise you can upload your own image.

So, like I said, I thought, “Great! I’ll just pull the image for PH&A from iTunes, and embed that in the FLAC files via XLD.” The first sign of trouble was that there was no apparent way to export a piece of album artwork directly from iTunes 11. Then I found out that the mp4v2 tool can extract art from AAC files—but it turns out the art isn’t stored in the AAC files. 2 So I dug around in ~/Music/iTunes/Album Artwork, which is not exactly laid out to tell you the exact path to the file you’re looking for, since its files and directories are named according to some numerical indexing scheme. However, since I’d only pulled this one artwork file this afternoon, I was able to find the exact culprit via a little shell command: ls -lR | grep "Mar .*7"3

Only problem is, the file is in this iTunes-proprietary ITC format. Neither the open command by itself, or forcing Preview to open it with open -a preview will make sense of the file as-is. Doing a bit of searching about, I found the tip that the ITC file may be a PNG file with a few extra binary headers. I brushed off my knowledge on editing binary files with vim, and upon opening the file, realized the file was a JPEG, given the presence of the “JFIF” marker rather than “PNG”. So popping open the file with vim -b, I changed this:

ITC file before conversion to JPEG
Click for a larger image.
The ITC file with the original binary header intact. Notice the word “data” is highlighted; everything from the beginning of the file until the end of this word should be deleted.

to this:

ITC file after conversion to JPEG
Click for a larger image.
The JPEG file after removing the ITC headers. Notice the two binary bytes remaining after the “JFIF” string.

by deleting everything from the beginning the file through the word “data”, leaving the two bytes before “JFIF” in place. Lo and behold, Preview could open our new JPEG file! From there it was a matter of just loading it into XLD and letting it rip:

Album art imported into XLD
Click for a larger image.
Shot of XLD preparing to rip People, Hell & Angels using the album art extracted from iTunes 11. You can import the JPEG containing the album art by right-clicking (or CTRL-clicking) on the blank image template and selecting “Load Image…”.

And to make sure the entire operation was a success, I played the album using the FLAC-aware Vox player:

Playing People, Hell & Angels and displaying its cover art using Vox
Click for a larger image.
Playing People, Hell & Angels using Vox, displaying its cover art imported from iTunes 11.

OK, mission accomplished! Now back to the business of studying and practicing…

…which is going extremely well, by the way! But every now and then, I welcome the excuse to take a break by indulging in my geeky tendencies and scribbling about them here—especially if Jimi’s somehow involved.

Footnotes

  1. I use a special build of DoubleTwist that can disable AAC-to-MP3 transcoding, since Android groks AAC. 

  2. I’d already installed mp4v2 using homebrew at some point. 

  3. Yes, there’s probably a thousand better, “more correct” ways to execute this command, perhaps using a brilliant invocation of find, but I’m not a programmer anymore, and this little quickie got me exactly what I wanted.