This is the Unix philosophy: Write programs that do one thing and do it well. —— Douglas McIlroy
I was dissatisfied with the state of Last.fm API integration in Ruby, and I decided to do something about it.
The Last.fm API has a whole load of interesting functionality, but the most useful one is scrobbling: pushing information about the music you’re listening to to Last.fm. The point of doing this is that you can:
- go back and work out what that song was that you liked; and
- make a note of the tracks that you like; and
- use statistics about you listening habits to recommend more music, or just to pick out a playlist for your portable player.
I’ve been listening to a fair bit of internet radio recently, and I’m hearing a lot of new (to me) music that I like. I’ve written some code to help me keep track (for Shoutcast servers, for example). One problem that I found was that there doesn’t seem to be any simple, working implementation of the basic scrobbling protocol for Ruby. The available libraries, like scrobbler-ng, seem to do everything but. I mean, scrobbler-ng claims to do it, but I couldn’t get it to work at all, and the code behind the scenes doesn’t seem to be hooked up to support basic scrobbling.
So I asked James what he’d used for his vinyl/Shazam/Last.fm hack, and he pointed me at some rough-and-ready code that (almost!) did the job.
I’ve taken it and tidied it up—well, rewritten it, really: I wrote some high level tests around the existing code, refactored it, then made the tests a bit more granular, then refactored it some more. And so, I give you SimpleScrobbler:
Scrobble tracks to Last.fm without wanting to gnaw your own arm off.
It’s pretty easy to use. It doesn’t do much. And it actually works.
- Previous: Making Korean pickles
- Next: How to paint over a rotten badger carcass (BBC News tabloid outrage edition)