Saturday, November 20, 2010

Scrobbling now from Kobol :)

In case you know about last.fm scrobbling and wondering what the hell is Kobol, well its a last.fm app that I created over the last weekend and named it such 'coz it just has such a nice ring to it. :) In case you are not familiar with BSG, its a planet in BSG world, so its something like saying 'scrobbling now from Krypton/Moon etc' :)

Its a rare thing for the lazy me to go create stuff like this, mainly 'coz -
  1. I'm lazy
  2. It should excite me a lot or should be a really very serious itch to overcome 1.
Last time it happened was while scratching my last.fm support for pidgin itch. In this case, it wasn't exactly my itch but rather my friend's itch that began it all.

Now my friend is what you call as a 'purist' and considers me as some sort of last.fm expert(mainly 'coz I introduced it to him I think). And so a month or two back he asks me -
'Playing your own library is fine but the songs get repetitive after a while, so how do I get last.fm to play more songs from the same artists and not any others'.
If you are not a last.fm subscriber, then you would know that there is very limited last.fm radios that you can listen to. You can listen to your library radio or similar artists radio etc but there is no way you can just listen to a selected artist radio i.e songs from only that artist and not from any other. And since my purist friend didn't want to corrupt his library by listening to other radios, I suggested to use we7 or spotify which have last.fm scrobbling integrated. But they turned out to be UK only services, some consolation win for us UK folks denied of Pandora! :)

Well anyway it was then that the evil idea stuck me, 'All you need to get songs in your library is to just scrobble them and to scrobble all you need is artist and track name, so effectively all you need is a program that scrobbles from such a file'. Sadly my friend didn't want to code and so I forgot all about it, as it wasn't my itch after all!


Which made me revisit that idea. One of the unpleasant tasks involved in the above idea is in creating the actual tracks file, where to get the data, who will copy paste etc. But then I saw Google Refine videos and I was like 'wow'! And I thought with the freebase integration it just takes matter of few clicks to create the artist-tracks file you want! Since I wanted to try out Google Refine, thought why not go ahead and implement that program after all, that way I too can get new artists that I wanted to listen to into my library ;) And while I was at it thought why not learn some basic python as well and thats how it started!

Soon after I started, I hit limitations in freebase, for one thing the artist names in Freebase weren't a perfect match with ones in last.fm. Also I couldn't figure out a way to get albums by an artist and tracks in that album, which was what had excited me in first place. Maybe I just needed to dig into the refine documentation a bit more but I was already bored.

So I just created a script that fetches the top tracks of a given artist from last.fm and writes to a csv. And you feed this csv to the other script which scrobbles the tracks in the csv. Now if anyone can find a good way to fetch the albums of an artist as well and the tracks in that album that will be brilliant!

If you are interested in scrobbling from a file, to listen to new artists or just to increase your scrobble count, then you can get the scripts here getTracks.py and lastfm.py . Only thing you need to do is obtain your own unique API_KEY and API_SECRET values from http://www.last.fm/api/account and replace the sample values in the script.

Since its from Kobol, this post has to end with

'so say we all'