August 17, 2013

8tracks, meet mpd. mpd, meet 8tracks.

At school, we use mpd to play music, and, largely, ncmpcpp for our mpd client. Though we have an extensive music library, sometimes the internet is our friend when it comes to music: some songs might only be available on youtube, for example. I use the 8tracks platform a lot at home and on the go to listen to music when I don’t feel like making up a playlist. This post will be about our method of queueing youtube videos and also the 8tracks mpd client which I wrote today.

First, you might be interested in how we queue youtube videos into mpd. There’s a neat program called quvi which parses various web pages and produces a stream; installing and looking at the man page will give you an idea of it’s use. The command we use to queue youtube videos is,

quvi “foo” —exec ‘mpc add %u’

(where foo is a youtube video link)

It wouldn’t be an exaggeration to say that integrating 8tracks is a lot more involved. Though there might be some way of hacking the flash stream of the 8tracks website, as quvi does with youtube links, doing it the vanilla way requires several queries to the 8tracks developer API and a small amount of library fiddling. It’s all pretty standard: one query to get the playlist data, one query to get a play token, and two queries per song (one to get the song, another to notify 8tracks of a “performance” of the song for royalties and such).

I don’t think that it would be sufficiently interesting to go through technical details; it was just a matter of typing the right incantations to python to have all the libraries (xml, urllib2, os.system, etc) and the 8tracks API fit together correctly. The script ended up being only about 120 lines, and the project can be found on my github account. If you’d like to use it, you’ll have to “create your own client” —- register as a developer to get an API key, plug it together with the script, and voila!

Remember to read the 8tracks terms of use and examine/edit the script as you see fit in order to be sure that your usage of the script doesn’t violate the aforementioned terms; I take no responsibility for your usage of my script.

Enjoy!