Another quick and dirty iTunes tagging script

Following up on this tweet, I downloaded the Holiday Obscura MP3s from Sound Opinions, a radio show run by Greg Kot and Jim DeRogatis, the rock music critics from the Chicago Tribune and the Chicago Sun-Times, respectively. It’s sort of a low-rent imitation of Siskel & Ebert, but for music instead of film.

The MP3s are, for the most part, a bunch of oddball songs with a Christmas theme. Unfortunately for iTunes users, the songs come in two long MP3s with the 15-16 tracks of each “side” run together in a single file. Ideally, you’d like to split them up into individual tracks and label them separately. This is a tedious process that I made relatively painless through a bit of scripting.

I split the files into individual songs with Fission. I’d like to be able to say I used Fission’s Smart Split feature to break up the tracks with a single command, but the silence between the tracks was too varied to make this practical. I was, however, able to scroll through and mark the splits pretty quickly. Then I saved each song into a file on my Desktop. I gave the files names that were easy to type and indicated the track number: A01.mp3, A02.mp3, and so on. I set up a new playlist in iTunes and imported the tracks from the Desktop into that playlist, taking care to preserve the order of the tracks.

Because the original MP3s were already tagged with a title and album artist, and because Fission preserves tags, the split tracks came into iTunes with useless names: all the tracks from the “Side A” MP3 were named “Side A,” and all the tracks from the “Side B” MP3 were named “Side B.” This is no good.

Fortunately, the track names and artists (when known) are given on the web page with the download links. There are basically three ways to get this information from the web page into iTunes:

  1. Read it off the web page and type it into iTunes. Eccch.
  2. Copy the title and artist for each track a paste it into iTunes. That’s two copies and two pastes for each track with a program switch in between. This is even more boring--and might even be slower--than typing it all by hand.
  3. Writing a script to automate the process.

Obviously, I chose #3. I resused some of the AppleScript from this old post to generate a script that would retag all the tracks from a given side. Here’s the script for Side A:

 1:  set tlist to {"Santa's Night Before Christmas", ¬
 2:    "Jingle Bells", ¬
 3:    "Six Tons Of Toys", ¬
 4:    "Sleigh Ride", ¬
 5:    "Boofo Goes Where Santa Goes", ¬
 6:    "The Imp", ¬
 7:    "Don't Intend To Spend Christmas Without You", ¬
 8:    "Send A Christmas Card To Joe", ¬
 9:    "Yingle Yingle Yumpin' Beans", ¬
10:    "Santa Claus Blues", ¬
11:    "Christmas Gift", ¬
12:    "Christmas Morning With The Cash Clan", ¬
13:    "Henry Had A Merry Christmas", ¬
14:    "Hoss Hoists A Toast", ¬
15:    "Winter Wonderland"}
16:    
17:  set alist to {"Unknown", ¬
18:    "The Three Suns", ¬
19:    "Dave Dudley", ¬
20:    "Lenny Dee", ¬
21:    "Linn Sheldon", ¬
22:    "Miss Ruth Roberts", ¬
23:    "Claudine Longet", ¬
24:    "\"Wee Bonnie\" Baker", ¬
25:    "Unknown", ¬
26:    "Sonny Boy Williamson", ¬
27:    "Margie Joseph", ¬
28:    "Johnny Cash", ¬
29:    "Walter Brennan", ¬
30:    "Lorne Greene", ¬
31:    "Chet Baker"}
32:  
33:  tell application "iTunes"
34:    set track_list to selection of browser window 1
35:    repeat with i from 1 to 15
36:      set this_track to item i of track_list
37:      set name of this_track to item i of tlist
38:      set artist of this_track to item i of alist
39:    end repeat
40:  end tell

The script for Side B was basically the same, but with different strings in tlist and alist.

At first glance, it may look like I’ve saved myself very little time--instead of copying from the web page into iTunes, I’ve copied into the Script Editor. But I actually generated the tlist and alist specifications with very little effort. I first copied the track info from the web page into TextMate and did a little editing to add “Unknown” as the artist to tracks that had no artist info. The Side A info looked like this:

Santa's Night Before Christmas - Unknown
Jingle Bells - The Three Suns
Six Tons Of Toys - Dave Dudley
Sleigh Ride - Lenny Dee
Boofo Goes Where Santa Goes - Linn Sheldon
The Imp - Miss Ruth Roberts
Don't Intend To Spend Christmas Without You - Claudine Longet
Send A Christmas Card To Joe - \"Wee Bonnie\" Baker
Yingle Yingle Yumpin' Beans - Unknown
Santa Claus Blues - Sonny Boy Williamson
Christmas Gift - Margie Joseph
Christmas Morning With The Cash Clan - Johnny Cash
Henry Had A Merry Christmas - Walter Brennan
Hoss Hoists A Toast - Lorne Greene
Winter Wonderland - Chet Baker

I then used this find & replace regular expression

which turned it into this:

"Santa's Night Before Christmas",¬
"Jingle Bells",¬
"Six Tons Of Toys",¬
"Sleigh Ride",¬
"Boofo Goes Where Santa Goes",¬
"The Imp",¬
"Don't Intend To Spend Christmas Without You",¬
"Send A Christmas Card To Joe",¬
"Yingle Yingle Yumpin' Beans",¬
"Santa Claus Blues",¬
"Christmas Gift",¬
"Christmas Morning With The Cash Clan",¬
"Henry Had A Merry Christmas",¬
"Hoss Hoists A Toast",¬
"Winter Wonderland",¬

Perfectly formatted for a single cut and paste into the definition of tlist in the Script Editor. Returning to TextMate and undoing to get back to the original file, I ran the find & replace again, but with a $2 instead of $1 in the replace field. This gave me

"Unknown",¬
"The Three Suns",¬
"Dave Dudley",¬
"Lenny Dee",¬
"Linn Sheldon",¬
"Miss Ruth Roberts",¬
"Claudine Longet",¬
"\"Wee Bonnie\" Baker",¬
"Unknown",¬
"Sonny Boy Williamson",¬
"Margie Joseph",¬
"Johnny Cash",¬
"Walter Brennan",¬
"Lorne Greene",¬
"Chet Baker",¬

which is formatted for pasting into the definition of alist. That’s three copy-and-pastes for each “side” instead of 30 or more.

So with a little AppleScript and a little regular expression knowledge, I was able to turn a tedious and frustrating operation into something that was almost fun. It was very satisfying to see the track and artist info change in iTunes as the script ran.

Tags: