The Code Train

Where Neil Crosby talks about coding on the train…

RSS Entries

Last Genius – A hack day project

Posted on December 18th, 2008 by Neil Crosby. Filed under Blog Posts.

Gosh, it’s thursday already? Last Sunday I attended‘s first open Hack Day near Brick Lane in London with the intention of building a system to allow creation of Genius Playlists using’s data.

For those of you who aren’t sure, a Genius Playlist is a playlist of music that all “works together” that’s created from one seed track of the user’s choice. Essentially, it’s a shortcut to creating playlists of stuff that suits how you’re feeling at that moment, rather than you having to go to the trouble of creating the playlist yourself.

Whilst I was initially sceptical of how well this would work (I’ve worked in this problem space before, so I know it isn’t awesomely easy), since iTunes gained this feature in v8 I’ve become more and more reliant on it. My reliance has been so great that I’ve expected the feature in all the other music based services I use. For example, when I started using Spotify, one of the first things I did without thinking was to start playing a track that I wanted to listen to and then look for the “genius” button to see what else Spotify would try and play for me. It upset me that this feature wasn’t there. Sure, Spotify and allow you to play radio stations based on a certain genre, artist or tag, but that misses a piece of perceived control that starting with a chosen song implies.

So, for’s hack day I decided to hack together a genius playlist creator. After all,’s API supplies the track.getSimilar method, which pretty much gives all the data you need for a genius playlist.

There were a few hurdles to get through though. First up was playlist creation and playback itself. It turns out that in you can only create actual playlists if you’re a paid subscriber to the service. That’s not a dealbreaker for me, so I paid my £1.50 for a month’s subscription to see how it went. Unfortunately, at that point I realised that whilst I could now create playlists, I could only play them back if they had at least 45 songs in them by at least 15 different artists. Oh, and I could only play them back in shuffle mode. On the website. Not in the desktop app or on the iPhone. Somewhat sub-optimal.

So, I went back to the drawing board. If I couldn’t do playlists how I wanted in, how about if I found the data I wanted in and then used Spotify to play it? Unfortunately, Spotify doesn’t yet have an API, so this also proved impossible.

Scratch Plan B then. Thankfully, I did have a Plan 9 available to me –’s ability to autostart tracks on the website by adding ?autostart to the end of any song page URL. Using this ability, I reckoned, I would be able to create a page containing a list of songs that could then be played in a browser window by loading up the individual song pages in a hidden iframe. Simplicity itsef, and as if by magic it actually worked!

There was, of course, more magic that went into creating Last Genius. Not all songs on the site are available to stream, and of those that are not all of them are full length tracks. Because I was playing the songs in iframes I had no way of knowing when a song had actually ended. I had to make sure that you didn’t end up hearing the same song twice in a playlist. All these things and more were hacked around during the hack day, and in the end I had something that actually worked.

The end result was a bookmarklet that you can stick into your browser toolbar and click to create a genius playlist any time you want. Just make sure you’re on a song page and a playlist will be created for you. If you’re not on a song page, lets just say that the system will try and find you some music that it reckons you’ll like.

Last Genius bookmarklet – drag onto your toolbar.

All I ask is that you remember that this is a hack. It’s only tested in Firefox 3 on the Mac, because during a hack day you don’t have time to make everything work everywhere (it’ll probably work elsewhere, I just haven’t tested yet). Because Last Genius has to make quite a few calls back to the mothership to set itself up, it might also take a little while to start up. Just be patient. For what it’s worth, I have plans to improve this over Christmas.

Because this is a toy I want for myself I plan to spend a bit more time making it nicer. With that in mind, if you have any ideas for things that will make it better, please let me know. Likewise, the source code is up on GitHub, so please go fork it and make improvements. Anything awesome I’ll very happily merge back into the trunk.

Tags: , , , ,

If you enjoyed this post, subscribe to The Code Train and read more when I write more.

9 Responses to “Last Genius – A hack day project”

  1. Hi Neil,

    congratulations on your excellent little app you hacked together.

    But why, oh why do we always have to listen to Rick?!?


  2. Because everyone loves Rick!

    Seriously though, if you go to a song page on (like maybe) and then use the bookmarklet you’ll have a much more pleasant experience.

  3. I used the bookmarklet on a song page and the first song still is Rick…

  4. Ah, I see the problem. You’re using whereas Last Genius expects you to be using

    I’ll push a fix :)

  5. There you go Patrick, it should be working for you (and people using in other countries too) now. Thanks for picking up on the bug for me!

  6. Is it possible to provide a XSPF playlist instead of playing the list in the browser? I’d like to integrate your service in my player shell-fm.

  7. I have to thank you for your blazingly fast fix.

  8. @shell-monkey – From the (admittedly small bit of) looking I did at XSPF before the hack day, it looked promising except for the part where only gives you a URL to the page the track is on, rather than a URL to a streamable track.

    If there’s a way to get at the streamable tracks then I’ll very happily produce an XSPF playlist.

  9. Denver Weckwerth Says:

    Thx for information.

Comments RSS

Leave a Reply

TheCodeTrain Theme by Neil Crosby, Powered by WordPress