Sunday, December 27, 2009

last.fm 2009

Last.fm has a cool API that let's you gewt almost any sort of data from them just using a web request in XML or JSON format. During their countdown for the top artists of 2009 they encouraged people to use the API, and I used the Last.fm API to show how many plays you scrobbled from each artist in the top 40.

http://zxcvbn.t35.com/lastfm-2009.html

Features:
  • Uses Last.fm API to get JSON data for number of songs listened to
  • Dynamic page effect using JavaScript to organize page elements
  • Uses last.fm javascript client API

The program is pretty simple, it uses the Library.getTracks API method to retrieve your listening data. I create a last.fm object. you need an 'API key' and 'API secret', which you 'apply' for on their API page http://www.last.fm/api. Then, you can call any of the methods of the API you like

Using my program as an example
/* Create last.fm object */
var lastfm = new LastFM(
{
apiKey: 'Apply for key at http://www.last.fm/api',
apiSecret: 'Apply for API code at http://www.last.fm/api',
cache: cache
});

/* Success function parses JSON data. note: stringify JSON data before parsing */
function success(json_data) {
var json_string = JSON.stringify(json_data);
var json_parse = JSON.parse(json_string);
var tracks = json_parse.tracks;
}

/* Failure function parses error codes */
function failure(code, message) {
alert(code + ': ' + message);
}

/* Call the api function with JSON format API parameters */
lastfm.library.getTracks({ user: "LastFM Username", artist: "Britney Spears" },
success_function_callback, failure_function_callback);


Update:
I made it so you can find out how many songs you've listened to by any artist you type in. It's not very easy to find out if the artist isn't in your top charts

http://zxcvbn.t35.com/lastfm-2009.html

No comments:

Post a Comment