August 25, 2005 at 3:00 PM by Dr. Drang
Yesterday, I imported a Harry Potter audiobook—an eight-CD set—into iTunes. Gracenote had two entries for most of the CDs, and the MP3 tags were in several formats. Sometimes the artist was J.K. Rowling, sometimes Jim Dale (the narrator). Sometimes the track name included chapter title, sometimes it was just “Chapter ##”. Sometimes the chapter title was in the artist field.
This was not what I wanted, but I didn’t relish hand-editing nearly two hundred tracks. (If you’re not familiar with the layout of these CDs, the producers break up the narration in to snippets that are usually no more than a few minutes long. It’s not uncommon for a chapter to have ten or more tracks.) Tonight I decided to dig into AppleScript for a fix. After looking at a couple of scripts from Apple’s collection, I put together this script:
tell application "iTunes" set track_names to "" set letters to "ABCDEFGHIJKLMNOPQRSTUVWXYZ" set chapter to "Chapter 1" set cname to " - The Worst Birthday" set track_list to selection of browser window 1 repeat with i from 1 to count of track_list set this_track to item i of track_list set fname to chapter & (character i of letters) & cname set name of this_track to fname set composer of this_track to "J.K. Rowling" set artist of this_track to "Jim Dale" set album of this_track to "Harry Potter and the Chamber of Secrets" end repeat end tell
(As you’ve probably guessed, I stuck a line break in the
set album ... line of the blog version so it would fit within the column. You’ll have to rejoin that line if you cut and paste this into the Script Editor.)
I start by selecting all the tracks of a chapter. The script then renames the selected tracks “Chapter 1A - The Worst Birthday”, “Chapter 1B - The Worst Birthday”, and so on. The artist is set to Jim Dale, the composer to J.K. Rowling, and the album name to the name of the book (without the “Disc ##” addendum that many of the Gracenote entries had). I then select the tracks of the next chapter, edit the
set chapter to ... and
set cname to ... lines, and run the script again.
If I add the time spent writing this post to the time spent writing and debugging the script, I probably didn’t save much time when compared to editing each track individually. But the script, once debugged, eliminates the errors that crop up when doing repetitive editing by hand and is much more fun to work on. The real time savings will come when I use this script as a template to retag other books.