npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-lastfm

v1.0.6

Published

simple last.fm api for node.js

Downloads

15

Readme

#Simple-Lastfm

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

Installation

npm install simple-lastfm

Examples

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',
	authToken: 'xxx' // Optional, you can use this instead of password, where authToken = md5(username + md5(password))
});

lastfm.getSessionKey(function(result) {
	console.log("session key = " + result.session_key);
	if(result.success) {
		lastfm.scrobbleNowPlayingTrack({
			artist: 'Ratatat',
			track: 'Seventeen Years',
			callback: function(result) {
				console.log("in callback, finished: ", result);
			}
		});
		lastfm.scrobbleTrack({
			artist: 'Bonobo',
			track: 'Black Sands',
			callback: function(result) {
				console.log("in callback, finished: ", result);
			}
		});
		lastfm.loveTrack({
			artist: 'Electrelane',
			track: 'Suitcase',
			callback: function(result) {
				console.log("in callback, finished: ", result);
			}
		});
		lastfm.unloveTrack({
			artist: 'something crap',
			track: 'no thanks',
			callback: function(result) {
				console.log("in callback, finished: ", result);
			}
		});
	} else {
		console.log("Error: " + result.error);
	}
});

#Documentation

init ( options )

options must be an object with the following required keys:

  • api_key
  • api_secret
  • username
  • password

Optional parameters:

  • session_key
  • debug

I recommend you save the session key and reuse it when possible. Debug should be true or false. By default it is false. Set it to true to have some console commands outputted.

getSessionKey ( callback )

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)

addTrackTags ( options)

Require parameters:

  • artist
  • track
  • tags: A comma delimited list of user supplied tags to apply to this track. Accepts a maximum of 10 tags.

Optional parameters:

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

scrobbleTrack ( options )

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.

loveTrack (options)

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']}.

unloveTrack (options)

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']}.

getArtistInfo (options)

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']}.

getSimilarArtists (options)

Required parameters:

  • artist

Optional parameters:

  • limit: The number of results to fetch per page. Defaults to 50.
  • autocorrect: [0, 1] Transform misspelled artist names into correct artist names, returning the correct version instead. The corrected artist name will be returned in the response.
  • mbid: The musicbrainz id for the artist.
  • callback: A function which receives a single object, of the form { success: true|false[, tags: {}, error: 'text description of the error']}.

getTags (options)

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']}.

getTopArtists (options)

Required parameters:

  • user

Optional parameters:

  • period: overall | 7day | 1month | 3month | 6month | 12month - The time period over which to retrieve top artists for.
  • limit: The number of results to fetch per page. Defaults to 50.
  • page: The page number to fetch. Defaults to first page.
  • callback: A function which receives a single object, of the form { success: true|false[, tags: {}, error: 'text description of the error']}.

getTrackInfo (options)

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']}.

getPlays (options)

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']}.