Sunday, December 16, 2012

Driving youtube using currently playing spotify tracks

I had the idea of using Spotify to drive youtube, basically providing a 'video jukebox' (although I hate that term!). Although it's a mash of different technologies, the implementation is pretty straight forward.



First, I used an apple script invoked from PHP to provide an XML webservice providing the currently playing track. Here's the script:

I then wrote a local HTML page that included an embedded Youtube Player. On startup the page would retrieve the currently playing track (using JQuery to call the aforementioned Webservice), query youtube (using the youtube search api), and then play the first search result in the embedded youtube player. It would then frequently check in with spotify and when the track changes, it will update the video. Here's the webpage:
This works quite well and even when in fullscreen the track automatically changes without interuption. There are a few issues though. Firstly, some tracks cannot be shown in the embedded player for copyright reasons. Secondly, sometimes the strategy of using the first youtube search result can be a bit hit and miss. To resolve this I think i'd need to add a hardcoded list of videos to use for particular spotify track IDs.

This could work quite well as a free-to-use website as the user's browser and youtube take the load - i'd just provide a HTML page. If only I could find a way to easily retrieve the currently playing spotify track that didn't cost me money. I could query last.fm using their neat web api, but they track usage per api account, not end user. This means that if multiple users used my embedded code, i'd quickly hit their fair use policy.