iRate.py v2007-06-29

The Problem:iTunes keeps song ratings, play and skip counts in a proprietary database format.The Solution:iTunes exposes song ratins, play and skip counts via AppleScript, and I have a python->AppleScript bridge.My solution of course is not a particularly original one, Doug’s AppleScripts for iTunes includes a Tags to File Comments script. Which uses AppleScript to take ratings, play counts, skip counts, and more out of iTunes and shove it into the Spotlight comment field in the extended attributes. This was a fine, perfectly well functioning script. However the performance characteristics of both AppleScript and extended attributes makes it very very slow. On my Core 2 Duo MacBook Pro it took roughly 8 hours (I don’t actually know, I fell asleep while waiting) to export the data for ~4,430 tracks, with iTunes using 100% CPU. I don’t know how long it takes to import the data because I figured I could write something else in less than 8 hours.So after about 4 hours of coding and debugging I present to you iRate.pyIt uses AppleScript to export the the ratings, played count, played date, skipped count, skipped date to an SQLite database. It will also import the same data from the SQLite database.  It also manages to be significantly faster than Doug’s script.  The export of my library takes about 44 seconds, and another 22 seconds to import.To run it requires:

  • MacOS X 10.4 (tested on 10.4.10)
  • iTunes 7.2+ (tested on 7.2 and 7.3)
  • Python 2.5 (Universal binary available here)
  • appscript 0.17.2 (Fancy installer available here)

So there we have a simple solution to a simple problem. Here is hoping someone else finds it as useful as I did.-David

Technorati Tags: ,

Tags: ,

One Response to “iRate.py v2007-06-29”

  1. has Says:

    FWIW, if you’re exporting a lot of tracks you can speed things up some more by reducing the number of commands you send to iTunes. e.g. Instead of doing:


    tracks = app('iTunes').browser_windows[1].view.file_tracks()
    for track in tracks:
    name = track.name()
    artist = track.artist()
    album = track.album()
    # do stuff here…

    which sends four commands for each track processed plus another command to get the initial list of track references, do this:


    tracksref = app('iTunes').browser_windows[1].view.file_tracks
    names = tracksref.name()
    artists = tracksref.artist()
    albums = tracksref.album()
    for name, artist, album in zip(names, artists, albums):
    # do stuff here…

    which sends four commands in total. The appscript manual has more info on this stuff, btw.

    HTH

Leave a Reply