Transparently rating iTunes tracks with Quicksilver

Apr 23, 10:21 AM

I was recently asked about what music I was liking now-a-days by a friend bemoaning the lack of musical cross-pollination since leaving the hallowed halls of our Alma Mater.

“Well, easy, sir!” I chortled, pulling up a quick search for my ‘starred’ music in iTunes. Hm. Out of 5573 tracks, I’d bothered to star about 10.

I ended up sending him to my last.fm profile but I’ve realized that there’s not a lot of relationship between ‘music I think is awesome’ and ‘music I listen to frequently.’ Because my normal mode is ‘shuffle’, and I have (see above) 5573 tracks, what shows up in last.fm is more or less randomly weighted by how many tracks I have from a given artist, and is no metric of quality.

So, I decided to rate more music. The problem is, I listen to music in the background and don’t want to bother myself pulling up itunes, finding the track playing now, deciding how many stars to give something, clicking that slot, and going back to what I was doing. Not going to happen. In fact, searching a bit for this problem, I found that this blog article perfectly captured both my annoyance at the star system AND provided the perfect solution.

So now if I like a track, I just pull up quicksilver with some magic that only my fingers remember (cmd-space iirc) and type what’s already turned into just ‘in…’ and boom, I bump the stars up by one.

Here it is, in action:

Fleshed out my sidebar: Running goals, books, flickr, oh my!

Jan 3, 06:38 PM

If you’re reading this in a feed reader, check out the main site . Using cobbled together time from lunch breaks and this weekend, I hand rolled it. I know I could have javascript included some of the feeds, but I wanted more control over the whole thing, so perl helped me out.

The runnerplus section is neat — it’s scraping the data from my profile (they don’t have feeds for what I wanted) and then doing the math on the goal I’ve set. I’m really, really, really loving running with my Nike+ kit I got for Christmas from my parents-in-law . It’s turning exercise into a measurable quantity, which seems to be the key my brain needed to push me hard. I’ve already gotten from being winded doing intervals of 60 seconds walking/90 seconds jogging…. to being able to jog solidly for 20 minutes. For anyone in any reasonable approximation of fitness, that’s not a big deal, but I’ve never been that fit.

Anyway, I’m also enjoying GoodReads — it’s amazing how many books I have going at a time, and it’s nice to have a way to feel that flow slip past.

I’ve also wanted to have flickr photos in my page for a while, but 1) I don’t like waiting for widgets to load, and 2) Amber and I both have accounts, and I wanted a way to ‘merge’ the feeds. (And (3), it was a chance to play more with CSS/jquery, which I’ve been meaning to learn more about.)

Anyway, I hope you enjoy having “what I’m up to” at your fingers — if not, at least I will. It’s “not quite done”, I want to style a bit more, add a few more features (linkedin, etc) — but it’s good enough for 0.01.

Interesting hacking around in python, OSX, and the iTunes Library

Jan 1, 08:56 PM

While working on a project for a friend, Amber accidentally deleted a playlist of music. “Uh oh”, she said, “it looks like you can’t undo that!”. A bit of googling showed that to be the case.

Thankfully, though it’s a bit out of date, we’ve been good(ish) about keeping backups. I thought “I bet I can get the playlist info out of the iTunes library file in the backup!” Sure enough, I mounted the drive, took a look, and there the data was. It wasn’t that useful though.

 <key>Name</key><string>The Special Playlist</string>
                        <key>Playlist ID</key><integer>14915</integer>
                        <key>Playlist Persistent ID</key><string>F668E7C09FF9F9AC</string>
                        <key>All Items</key><true/>
                        <key>Playlist Items</key>
                        <array>
                                <dict>
                                        <key>Track ID</key><integer>3533</integer>
                                </dict>
                                <dict>
                                        <key>Track ID</key><integer>3532</integer>
                                </dict>
                                <dict>
                                        <key>Track ID</key><integer>3527</integer>
                                </dict>

So normally I break out the perl here, and it looked like there was some CPAN modules to get it done, but the iTunes XML parser library looks like it wasn’t packaged right and I couldn’t install it via CPAN, blah blah blah. I’ve been trying to break out the python more often, so searched for ‘python itunes xml library parse’ and found this gem from 2005:

Airport Express Hates Me

In which the author uses a neat trick (the Python/Objective C bindings) to parse the iTunes library. After a bit of a bumpy start, I ended up with the following code:

#!/usr/bin/python
from Foundation import *
dbFile = “itunes_from_backup.xml”
db = NSDictionary.dictionaryWithContentsOfFile_(dbFile)
printtrack = {}

for playlist in db[u’Playlists’].itervalues(): if playlist[u’Name’] == u“The Special Playlist”: for track in playlist[u’Playlist Items’].itervalues(): printtrack[track[u’Track ID’]] = 1

for track in db[u’Tracks’].itervalues(): try: if printtrack[track[u’Track ID’]]: print “%s: %s, %s” % (track[u’Artist’], track[u’Album’], track[u’Name’]) except: pass

Which yeilds a nice list like:
Andrew Bird: Armchair Apocrypha, Scythian Empires
Andrew Bird: Armchair Apocrypha, Self-Torture
Andrew Bird: Armchair Apocrypha, Simple X
Andrew Bird: Armchair Apocrypha, Spare-Ohs
Andrew Bird: Armchair Apocrypha, The Supine
Andrew Bird: Armchair Apocrypha, Yawny at the Apocalypse
Arcade Fire: Funeral, Crown Of Love
Arcade Fire: Funeral, Haiti
Arcade Fire: Funeral, In The Backseat
Arcade Fire: Funeral, Neighborhood 1 – Tunnels
Arcade Fire: Funeral, Neighborhood 2 – Laika

I think there is a way to look up track information from track ID’s directly, but I couldn’t suss it, hence the double loop with the dictionary for bookkeeping. (Yes, my python looks very perlish, I’m sure.) In any case, the Python Objective C bindings look pretty cool and I plan to explore those further.