My first step in the audio project was to see if I could actually figure out a way to control Pandora. If you’re not aware, Pandora is an incredible music service which allows you to create “stations” based on music that you like. It will then play other songs that it thinks you might like. You can thumbs up or down songs and it will refine the songs it plays accordingly.
Anyway, I need to be able to change the stations remotely from a web interface on my phone. To do that I searched for an API of some sort. This was hard because the only thing I was able to find was a reference to a 2.0 api but no further details. I eventually gleaned that this “API” was actually an undocumented set of javascripts accessible from the pandora site. The javascripts are actually what Pandora uses to control content.
I read through the js files and realized that if I could get some of the javascript functions to execute that I would be in great shape. Pandora allows you to switch stations from your profile page. Although the player itself is a flash object which is inaccessible by the average bear (mostly me) the profile page is straight HTML. It has links that execute js which changes the player on the player page. My first idea was to create an html frameset. From one frame I would execute the js in the frame that holds the pandora profile info. Well, of course that was a waste of time since I quickly figured out that javascript security will not allow a script from one domain to execute a function from a script in another domain. Good to prevent hackers, bad for me! Strike one.
I was undeterred. I use Firefox and am a big fan of the greasemonkey plugin. The Greasemonkey plugin allows you to manipulate a page as it is loading and before it renders. You can add or remove elements, and all kinds of other shenanigans. Before you could wash a greasy monkey I had injected a little js in the page which would execute the pandora function for changing the currently playing station. A few more lines of code and I was able to add an HTML parameter to the url of the profile page with the pandora station ID, and strip that out with greasemonkey and embed it into the pandora function I had gotten to work previously. So now a url www.pandora.com/profileurl/?sttn=09990089899 (not a real url) for example, would cause the pandora player to switch to the station associated with the id 09990089899. It was magical, and life was good. Now I just have to figure out the rest of the stuff. Detail, details.