alex chiang: web 6.0

March 25, 2007

RuFF-iTunes

Filed under: dreck — alex @ 10:33 pm

ABOUT
This is a collection of scripts to manage your music tracks from within iTunes. If you have an album whose tracks have incomplete or missing tag information, these scripts can:

  • pull information from freedb.org
  • add the id3 tag information to the album’s tracks

These scripts will only work on a Mac, since AppleScript is involved.

INSTALL
First, I assume that you know your way around a unix shell (aka the terminal). If you don’t, I apologize for the seemingly terse documentation. Perhaps someone else out there in internet-landia can write some more user-friendly instructions.

Next, a prerequisite. You will need to download and install rb-appscript.

After you have accomplished that task, go ahead and download RuFF iTunes. You will need to copy both AppleScript files to your iTunes script library, typically located in:

  ~/Library/iTunes/Scripts/

Finally, you will need to copy itunes_freedb.rb to /opt/local/bin.

You may want to restart iTunes just for kicks.

USAGE
This is not the world’s simplest workflow, but it does work, and sure beats typing all the data into iTunes manually, so bear with me.

First, you need to select all the tracks in the album for which you are interested in normalizing.

Caveat: we assume that the tracks in the album are in numerical order! If they are not, I do not recommend running this script, as I’ve not tested what happens in this case.

Next, create a playlist with those tracks. This can be accomplished by the key combination: control-shift-n

Select the playlist, then select the first track in the playlist.

Select the Firefox Search Freedb menu item, from the script icon in the iTunes menu bar. You will be prompted on a field to search on.

Firefox will then search freedb.org for the track information. This step is where human intervention is necessary. Click around until you find the album which seems to match up with the tracks you have in your iTunes library. On the line that says “Disc-ID”, there is a link to a funny looking combination of letters and numbers.

Copy that link location to the clipboard.

Return to iTunes, and select the other script from the iTunes menu bar, called Save Freedb Results. Paste the URL you just copied into the entry box. If all goes well, your tracks will be renamed, and any additional information, such as Year and Genre will be added, if available.

TODO
Are you kidding me? Look at how long and complicated the install and usage sections are. This is due to the fact that I just wanted a quick and dirty solution for myself, and I’m willing to live with quite a bit of ugliness in my life.

Seriously though, my set of scripts was based heavily upon the
CDDB Safari Kit written by Doug Adams, and that kit is the basis for the two-step AppleScript ugliness. I alone am responsible for adding the third ugly step.

If I were to spend more time improving this, I’d probably think about:

  • writing better documentation
  • making some sort of installer
  • including the rb-appscript package with my package
  • adding error checking
  • giving the user an option to choose which web browser to use
  • removing the requirement that tracks must be in album order (probably would work if you at least had the track names, but in alphabetical order and were missing track number information)
  • making the installation location of itunes_freedb.rb configurable

Improvements are welcomed.

LICENSE
This set of three scripts is released under the GPL v2 and comes as-is. No warranties are expressed or implied.

I’ve tested it on my machine, and it works, but no guarantees that it will work on yours. Please don’t come crying to me if these scripts erase all your music and your mac blows up and you start getting tons of crazy spam (not so bad) but you actually start reading it all (pretty darn bad).

web 2.0 baby! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Facebook
  • e-mail
  • Reddit
  • Technorati

3 Responses to “RuFF-iTunes”

  1. alex chiang: web 6.0 » pointer to RuFF iTunes Says:

    [...] spent an hour or so writing RuFF-iTunes over the [...]

  2. has Says:

    Sounds interesting. How does it compare to using iTunes’ Advanced > Get CD Track Names option?

    “”"”getting the “Save Freedb Results” AppleScript to call the itunes_freedb ruby script (currently doesn’t work for reasons unknown)”"”

    When you run a script from iTunes’ script menu, iTunes can’t handle Apple events sent by other processes until that script finishes. This isn’t a problem for menu scripts that send events directly to iTunes (e.g. AppleScripts, PyOSA scripts), but here you’re using ‘do shell script’ to run an external ruby process which then tries to send events to iTunes - and so they end up blocking each other.

    However, since calling ‘do shell script’ is the last thing your AppleScript does, you can get around this problem by having ‘do shell script’ return immediately without waiting for the ruby script to complete first. Just redirect its stdout and stderr to /dev/null, e.g.:

    do shell script “your-command > /dev/null 2>&1 &”

    If your Ruby script needs to report errors or anything else to the user, you can use the OSAX module and Standard Additions’ display_dialog command to pop up a dialog in iTunes; see the OSAX manual for details.

    HTH

  3. alex Says:

    You can only use the built-in Advanced -> Get CD Track Names option if you used iTunes to import the disc. Trying to do so with mp3s created via a different method results in iTunes giving you an error.

    Thanks for the tip on backgrounding the process and redirecting the output. I’ll incorporate that idea into the next version.

    /ac

Leave a Reply