simple-lastfm

simple last.fm api for node.js

#Simple-Lastfm

A simple nodejs library to interface with the last.fm API

First, you'll need to get an API key from last.fm: http://www.last.fm/api/account.

Once you have your API key and API secret, you'll need to generate a session key, after which you can then start to scrobble:

var Lastfm = require('./simple-lastfm/');
 
var lastfm = new Lastfm({
    api_key: 'xxx',
    api_secret: 'xxx',
    username: 'xxx',
    password: 'xxx'
});
 
lastfm.getSessionKey(function(result) {
    console.log("session key = " + result.session_key);
    if(result.success) {
        lastfm.scrobbleTrack({
            artist: 'Bonobo',
            track: 'Black Sands',
            callbackfunction(result) {
                console.log("in callback, finished: ", result);
            }
        });
        lastfm.loveTrack({
            artist: 'Electrelane',
            track: 'Suitcase',
            callbackfunction(result) {
                console.log("in callback, finished: ", result);
            }
        });
    } else {
        console.log("Error: " + result.error);
    }
});

#Documentation

options must be an object with the following required keys:

  • api_key
  • api_secret
  • username
  • password

Optional parameters:

  • session_key

I recommend you save the session key and reuse it when possible.

callback: A function which receives a single object. On success, this object looks like:

    {
        success: true,
        session_key: 'xxx'
    }

On failure:

    {
        success: false,
        error: 'A text description of the error from last.fm'
    }

Note:Right now When a session key is successfully received, it automatically gets saved into the lastfm instance (in the above code, you could access it as lastfm.session_key)

Required parameters:

  • artist
  • track

Optional parameters:

  • callback: A function which receives a single object, of the form { success: true|false[, error: 'text description of the error']}.
  • timestamp: The timestamp for this scrobble. If omitted, uses the current date/time. Use number of seconds (NOT milliseconds!) since the UNIX epoch.

Required parameters:

  • artist
  • track

Optional parameters:

  • callback: A function which receives a single object, of the form { success: true|false[, error: 'text description of the error']}.

Required parameters:

  • artist

Optional parameters:

  • callback: A function which receives a single object, of the form { success: true|false[, artistInfo: {}, error: 'text description of the error']}.

Required parameters:

  • artist
  • track

Optional parameters:

  • callback: A function which receives a single object, of the form { success: true|false[, trackInfo: {}, error: 'text description of the error']}.

Required parameters:

  • artist

Optional parameters:

  • track
  • callback: A function which receives a single object, of the form { success: true|false[, tags: {}, error: 'text description of the error']}.

Required parameters:

  • artist

Optional parameters:

  • track: The name of the track. If ommitted, method will return number of artist plays.
  • callback: A function which receives a single object, of the form { success: true|false[, plays: #, error: 'text description of the error']}.