Fixing audiobook track titles (again)

I decided to relisten to the audiobook of Harry Potter and the Deathly Hallows, so I did the usual iTunesy stuff and synced the first few chapters to both my iPhone and my old second-generation iPod nano. When the syncing was done and I looked at both devices to make sure everything had worked, I realized I needed to make some changes to the track titles.

You see, I’m still working my way through Sean Wilentz’s Dylan book and the track titles of the two books have enough similarities to be confusing. Having two books on the iPhone is no big deal, as its user interface does a good job in keeping them separate.

In fact, the track titles as they appear in iTunes don’t even show up on the iPhone.

But it’s a different story on the nano. The nano puts all the book tracks together in the Audiobook category. Because these books were ripped from CDs, there are several tracks for each chapter, and they have names like “Chapter 01A - The Dark Lord Ascending.”1 On the nano’s small screen, the “Chapter 01A” part takes up most of the width, making it harder than it should be to distinguish between the two books. What I needed was a set of track names that had both the book name and the chapter/track info in the first several characters. Time to write a script.

I suppose I could have written it in AppleScript, but in my mind “AppleScript” and “search and replace” are phrases that aren’t tres bien ensemble. So I wrote the script in Python using the appscript library. Here it is:

 1:  #!/usr/bin/python
 3:  import appscript
 5:  selected ='iTunes').selection.get()
 7:  for t in selected:
 8:    oldname =
 9:    newname = oldname.replace('Chapter', 'HP7 - Ch', 1)

I selected all the Deathly Hallows tracks and ran the script to apply the changes. I then made the obvious edits and ran it on all the other Potter books and on the Dylan book, too.

(Why does Line 9 use a third argument of 1 in the replace method? That’s a bit of defensive programming I thought of after changing the Deathly Hallows track titles. If some of the tracks had had names like

Chapter 52C - The Final Chapter

they would have turned into

HP 7 - Ch 52C - The Final HP7 - Ch

which was not what I was looking for. The third argument limits the replacement to the first “Chapter” found in the title.)

The script made short work of an otherwise long and tedious process, and now I have tracks that can be distinguished at a glance.

  1. The track names in the Dylan audiobook were more or less in this form when I ripped the disks. The Potter track names, on the other hand, were originally a mess, and I had to wrangle them into this form using an AppleScript described in this ripe old post. Such are the vagaries of the Gracenote database

4 Responses to “Fixing audiobook track titles (again)”

  1. Tony McDaniel says:

    You may want to check out Audiobook Builder

    I use it for converted ripped audiobooks into the proper format for iTunes with support for bookmarks, etc. You can either use it to rip the CDs or load your existing mp3 files. The interface is a bit clunky, but it gets the job done.

  2. Dr. Drang says:

    Tony, thanks for the link. My first instinct is to dismiss utilities like Audiobook Builder as unnecessary–too seldom used to be worth either their cost or their space on my hard drive. But when I saw that it was only $10, I had second thoughts. Next time I need to rip an audiobook, I’ll take it for a test drive and see if it does what I need.

    One caveat: Although the many tracks per chapter of a typical CD audiobook are a pain, I think having separate tracks for each chapter is worthwhile. The description says Audiobook Builder collects the whole book into one or two tracks. If that can’t be changed with a simple preference, I won’t want to use it.

  3. Christina Warren says:

    As if my geek crush on your blog wasn’t already gargantuan…

    I’m not embarrassed to admit that I’ve created similar (let yes elegant) solutions using AppleScript for my few non-Audible audio books. Audible can be a PITA, but the advantage is that it does usually make things like this not happen.

    What kills me is that there are times when something will show up just fine in iTunes, like in terms of sorting and track numbers/chapters, but on the iPod or iPhone, it ends up being totally fucked, requiring a manual and complete meta-data rebuild.

  4. Dr. Drang says:

    Although I don’t complain in the post about the way the iPhone displays the track information, I think what’s shown in the second screenshot is really stupid. They don’t tell you anything about the track name, and—unbelievably—the “Part n of N” names get repeated. Checking my phone just a minute ago, I found three tracks identified as “Part 1 of 53” in the Bob Dylan book.

    Fortunately, if you start any of the tracks playing and then tap the “flip around” button in the top left corner, you see the track names as they’re displayed in iTunes. But why you don’t see them before you play a track is a mystery.