So we listen to music on speakers – not headphones – quite a bit in the studio. Or at least Jack does, because they’re in his batcave.

And sometimes, I’m not sure what’s playing from next door, but I know I like it – and it’d be good to know what it is. Fortunately, Jack mainly listens to last.fm radio (and even if it’s not radio, his iTunes would still be scrobbled).

So I wrote wotlisten.rb. You can see it (and get it) as a gist on github. It doesn’t use audio recognition, or the last.fm API, or RSS; it uses plain-old screen-scraping.

(Somewhere near the top of my list of coding tools is Hpricot, because it’s a lovely HTML parser that you can scrape with as fast as you can think. Or, at least, as fast as you can write selectors. That was the case here.)

So: you throw in a username, and wotlisten.rb tells you what they’re listening to. Or what they were last listening to. It doesn’t distinguish between the two – and why should it? This is Situated Software at its most useful: I assume you can hear the music that’s playing, and that you know the last.fm tag for the user playing it (and: until very recently, I assumed that person was Jack Schulze; this updated 2.0 release lets you pass in any username).

It’s unremarkable code in the extreme, but notable for the fact it took ten minutes to bang it out; it came out as fast as I could think it. I’m getting to the point where, especially with Hpricot and similar, this kind of tools is second-nature to write. It’s taken a long while to get there, though.

The script proved useful upon several occasions that day. More to the point, it paid for itself handsomely a few hours later, when we discovered that Schulze was playing Bonnie Tyler’s Holding Out For A Hero.

1 comment on this entry.

  • James Wheare | 22 Feb 2009

    You’ll want to gsub out “free download” too. Or just any “small” tags. But that may be too much like unneeded effort :)