Monday, November 19, 2012

How old are these songs?

I'm constantly looking for new music - the upbeat kind that gets the energy flowing for coding. I used to listen to the station "93X", but I've noticed that their song catalog is becoming increasingly antiquated.  Since that's just a guess, it seemed prudent to verify the hypothesis using a little "cloud magic".

Gathering the current song data

On the station's website, they have a "ticker" that lists the currently playing song. Using Firebug "Net" panel, it looks like the Javascript code has a timer that polls the site every 15 seconds for the current song's artist and title.  The URL request looks like this:

http://www.93x.com/jsfiles/NowPlaying.aspx?lid=5163&source=http%3A%2F%2Forigin%2Emedia%2Eradcity%2Enet%2Fkxxr%2Fnowplaying%2Fnowplaying93%2Exml&refresh=15&5927.663631614869

The response is something like this:


<!--
Cached Data


-->
<div id="nowPlayingArtist">SOUNDGARDEN</div></hr>
<div id="nowPlayingSong">BLACK HOLE SUN</div>

Yeah, that's right, it's 2012, and they're still playing "Black Hole Sun" (hey, I like the song too - but a bit less than when it was released in the early/mid 90's).

Now that we have a "easy" way of obtaining the current artist/song information, the next step is to find out the release date. Fortunately, Apple's dominance of the recorded music business comes in handy here. iTunes makes it easy to search for something - they even have a convenient API guide: http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html 

Thus, the search URI looks something like this:  https://itunes.apple.com/search?media=music&term=SOUNDGARDEN+BLACK+HOLE+SUN

The result is a JSON array (very nice!) containing 43 matches. The hard part here is going to be finding the "correct" entry among all of the values. It seems that the "ideal" way to accomplish this is to find the object(s) which match (case insensitive!) these property values:
"trackName":"Black Hole Sun", 
"artistName":"Soundgarden", 

In this case, there's a few "correct" matches, and each has a different release date:
"releaseDate":"2010-09-28T07:00:00Z", 
"releaseDate":"1994-02-28T08:00:00Z", 

In this case, the "solution" is to simply pick the oldest release date.

Saving it for later

The next part is accumulating that information and storing (persisting) it so that an continual analysis can be performed. Otherwise, it's possible that a particular DJ may prefer the "classic" songs over the newer ones, and thus would skew the overall results.  The big question here is "what's the average age of the songs played on this station?"

Since this is being stored "in the cloud", a few options are available.

  • Google App Engine Datastore, which is effectively a key/object store. 
  • MongoDB, a document store 
  • Something relational, like AWS RDS, Microsoft SQL, or Google Cloud SQL 


For this trivial app (small amount of persistence), any of them will suffice. More on that, and the eventual code/implementation coming later.

No comments:

Post a Comment