I came across some very neat Last.fm stats visualizations some times ago, and wanted to try out some ideas in JavaScript (probably with Processing.js). I couldn’t find any efficient way to use their API from JS, so I made MooFm…

What is it?

MooFm is a little (<5Ko) MooTools plugin making access to this data as easy as it can be. It lets you get the stats asynchronously without having to deal with query concatenation or Ajax calls.

How do I use it?

Let’s say we want to get the most popular album of Nirvana. Taking a look at the last.fm API guide, we find the documentation for the artist.getTopAlbums method.

// just give MooFm your API key...
var moofm = new MooFm('b25b959554ed76058ac220b7b2e0a026');

var callback = function(resp) {
   // will output "Nevermind"

// methods' name and params are the same as in last.fm doc
moofm.artist.getTopAlbums({'artist':'Nirvana'}, callback);

Couldn’t be simpler, right? All Last.fm readonly methods are accessible this way.

Getting started

To get started you’ll need a recent version of MooTools (obviously), the MooFm.js library and its proxy. Now get an API key (free), and you’re good to go.

Demo time!

Here is a little demo I put together as an example.