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

lastfm-njs

v2.0.1

Published

A complete last.fm API for Node.JS

Downloads

122

Readme

LastFM-njs

A fully featured interface for Node and the Last.FM api

The full Last.FM API description can be found here

You'll need an API key from Create API Account

You can install using npm install --save lastfm-njs

Then you can set up like so, where username is a default username:

var lastfm = require("lastfm-njs");
var config = require("./config");
var lfm = new lastfm.default({
  apiKey: config.key,
  apiSecret: config.secret,
  username: config.username,
});

If a method requires writing to an account, then you also need a password

var lfm = new lastfm.default({
  apiKey: config.key,
  apiSecret: config.secret,
  username: config.username,
  password: config.password,
});

This library supports both esm and cjs importing, commonjs will export as a default. You can use modules like

import LastFM from 'lastfm-njs';

const client = new LastFM(...)

or require with

const LastFM = require("lastfm-njs");

const client = new LastFM.default(...)

After this, you can use any of the methods

Documentation

All methods use promises

lastfm
  .auth_getMobileSession()
  .then(function (result) {
    lastfm
      .album_addTags({
        artist: "Oh Pep!",
        album: "Living",
        tags: "peppy,folk,music",
      })
      .then(printRes)
      .catch(printError);
  })
  .catch(printError);

See example files for other examples

Authentication

Last.FM Documentation

A username and password is required

auth_getMobileSession();

which either returns

{
    success: true,
    key: 'XXX'
}

or

{
    success: false,
    error: [lastFMError]
}

Album Methods

Examples

Add Tags*

Last.FM Documentation

album_addTags(opt), where

opt = {
  artist: artist, //req
  album: album, //req
  tags: tags, //req, max: 10, comma separated list
};

*Requires Authentication

Get Info

Last.FM Documentation

album_getInfo(opt), where

opt = {
  artist: artist, //req unless mbid
  album: album, //req unless mbid
  mbid: mbid, //opt
  lang: lang, //opt
  username: username, //opt
};

Get Tags

Last.FM Documentation

album_getTags(opt), where

opt = {
  artist: artist, //req unless mbid
  album: album, //req unless mbid
  username: username, //req
  mbid: mbid, //opt
};

Get Top Tags

Last.FM Documentation

album_getTopTags(opt), where

opt = {
  artist: artist, //req unless mbid
  album: album, //req unless mbid
  mbid: mbid, //opt
};

Remove Tag*

Last.FM Documentation

album_removeTag(opt), where

opt = {
  artist: artist, //req
  album: album, //req
  tag: tag, //req, single tag to remove
};

*Requires Authentication

Album Search

Last.FM Documentation

album_getTopTags(opt), where

opt = {
  album: album, //req
  limit: limit, //opt, defaults to 30
  page: page, //opt, defaults to 1
};

Artist

Examples

Add Tags*

Last.FM Documentation

artist_addTags(opt), where

    opt = {
        artist: artist //req
        tags: tags, //req, max 10, comma separated
    }

*Requires Authentication

Get Correction

Last.FM Documentation

artist_getCorrection(opt), where

opt = {
  artist: artist, //req
};

Get Info

Last.FM Documentation

artist_getInfo(opt), where

opt = {
  artist: artist, //req unless mbid
  mbid: mbid, //opt
  username: username, //opt
};

Get Similar

Last.FM Documentation

artist_getSimilar(opt), where

opt = {
  artist: artist, //req unless mbid
  mbid: mbid, //opt
  limit: limit, //opt
};

Get Tags

Last.FM Documentation

artist_getTags(opt), where

opt = {
  artist: artist, //req unless mbid
  user: username, //req
  mbid: mbid, //opt
};

Get Top Albums

Last.FM Documentation

artist_getTopAlbums(opt), where

opt = {
  artist: artist, //req unless mbid
  mbid: mbid, //opt
  page: page, //opt, default is 50
  limit: limit, //opt, default is 1
};

Get Top Tags

Last.FM Documentation

artist_getTopTags(opt), where

opt = {
  artist: artist, //req unless mbid
  mbid: mbid, //opt
};

Get Top Tracks

Last.FM Documentation

artist_getTopTracks(opt), where

opt = {
  artist: artist, //req unless mbid
  mbid: mbid, //opt
  page: page, //opt, default is 1
  limit: limit, //opt, default is 50
};

Remove Tag*

Last.FM Documentation

artist_removeTag(opt), where

    opt = {
        artist: artist //req
        tag: tag, //req, 1 tag to be removed
    }

*Requires Authentication

Search

Last.FM Documentation

artist_search(opt), where

opt = {
  artist: artist, //req unless mbid
  page: page, //opt, default is 1
  limit: limit, //opt, default is 50
};

Chart Methods

Examples

Get Top Artists

Last.FM Documentation

chart_getTopArtists(opt), where

opt = {
  page: page, //opt, default is 1
  limit: limit, //opt, default is 50
};

Get Top Tags

Last.FM Documentation

chart_getTopTags(opt), where

opt = {
  page: page, //opt, default is 1
  limit: limit, //opt, default is 50
};

Get Top Tracks

Last.FM Documentation

chart_getTopTracks(opt), where

opt = {
  page: page, //opt, default is 1
  limit: limit, //opt, default is 50
};

Geo Methods

Examples

Get Top Artists

Last.FM Documentation

geo_getTopArtists(opt), where

opt = {
  country: country, //req, ISO 3166-1 format
  page: page, //opt, default is 1
  limit: limit, //opt, default is 50
};

Get Top Tracks

Last.FM Documentation

geo_getTopTracks(opt), where

opt = {
  country: country, //req, ISO 3166-1 format
  page: page, //opt, default is 1
  limit: limit, //opt, default is 50
};

Library Methods

Examples

Get Artists

Last.FM Documentation

library_getArtists(opt), where

opt = {
  user: username, //req
  page: page, //opt, default is 1
  limit: limit, //opt, default is 50
};

Tag Methods

Examples

Get Info

Last.FM Documentation

tag_getInfo(opt), where

opt = {
  tag: tag, //req
  lang: lang, //opt
};

Get Similar

Last.FM Documentation

tag_getSimilar(opt), where

opt = {
  tag: tag, //req
};

Get Top Albums

Last.FM Documentation

tag_getTopAlbums(opt), where

opt = {
  tag: tag, //req
  limit: limit, //opt, default is 50
  page: page, //opt, default is 1
};

Get Top Artists

Last.FM Documentation

tag_getTopArtists(opt), where

opt = {
  tag: tag, //req
  limit: limit, //opt, default is 50
  page: page, //opt, default is 1
};

Get Top Tags

Last.FM Documentation

tag_getTopTags(opt), where

opt = {};

Get Top Tracks

Last.FM Documentation

tag_getTopTracks(opt), where

opt = {
  tag: tag, //req
  limit: limit, //opt, defaults to 50
  page: page, //opt, defaults to 1
};

Get Weekly Chart List

Last.FM Documentation

tag_getWeeklyChartList(opt), where

opt = {
  tag: tag, //req
};

Track Methods

Examples

Add Tags*

Last.FM Documentation

track_addTags(opt), where

opt = {
  artist: artist, //req
  track: track, //req
  tags: tags, //req, max: 10
};

*Requires Authentication

Get Correction

Last.FM Documentation

track_getCorrection(opt), where

opt = {
  artist: artist, //req
  track: track, //req
};

Get Info

Last.FM Documentation

track_getInfo(opt), where

opt = {
  artist: artist, //req unless mbid
  track: track, //req unless mbid
  mbid: mbid, //opt
  username: username, //opt
};

Get Similar

Last.FM Documentation

track_getSimilar(opt), where

opt = {
  artist: artist, //req unless mbid
  track: track, //req unless mbid
  mbid: mbid, //opt
  limit: limit, //opt
};

Get Tags

Last.FM Documentation

track_getTags(opt), where

opt = {
  artist: artist, //req unless mbid
  track: track, //req unless mbid
  username: username, //req
  mbid: mbid, //opt
};

Get Top Tags

Last.FM Documentation

track_getTopTags(opt), where

opt = {
  artist: artist, //req unless mbid
  track: track, //req unless mbid
  mbid: mbid, //opt
};

Love Track*

Last.FM Documentation

track_love(opt), where

opt = {
  artist: artist, //req unless mbid
  track: track, //req unless mbid
};

*Requires Authentication

Remove Tag*

Last.FM Documentation

track_removeTag(opt), where

opt = {
  artist: artist, //req
  track: track, //req
  tag: tag, //req, single tag to remove
};

*Requires Authentication

Scrobble*

Last.FM Documentation

track_scrobble(opt), where

opt = {
  artist: artist[i], //req
  track: track[i], //req
  timestamp: timestamp[i], //req
  album: album[i], //opt
  context: context[i], //opt
  streamId: streamId[i], //opt
  chosenByUser: chosenByUser[i], //opt
  trackNumber: trackNumber[i], //opt
  mbid: mbid[i], //opt
  albumArtist: albumArtist[i], //opt
  duration: duration[i], //opt
};

*Requires Authentication

Search

Last.FM Documentation

track_search(opt), where

opt = {
  track: track, //req
  artist: artist, //opt
  limit: limit, //opt, defaults to 30
  page: page, //opt, defaults to 1
};

Unlove*

Last.FM Documentation

track_unlove(opt), where

opt = {
  track: track, //req
  artist: artist, //req
};

*Requires Authentication

Update Now Playing*

Last.FM Documentation

track_updateNowPlaying(opt), where

    opt = {
        artist: artist, //req
        track: track, //req
        album: album, //opt
        context: context //opt
        trackNumber: trackNumber, //opt
        mbid: mbid, //opt
        albumArtist: albumArtist, //opt
        duration: duration, //opt
    }

*Requires Authentication

User Methods

Examples

Get Artist Tracks

Last.FM Documentation

user_getArtistTracks(opt), where

opt = {
  user: username, //opt
  artist: artist, //req
  startTimestamp: startTimestamp, //opt defaults to all time
  page: page, //opt, default is 1
  endTimestamp: endTimestamp, //opt defaults to all time
};

Get Friends

Last.FM Documentation

user_getFriends(opt), where

opt = {
  user: username, //opt
  recentTracks: recentTracks, //opt, true|false
  limit: limit, //opt defaults to 50
  page: page, //opt, default is 1
};

Get Info

Last.FM Documentation

user_getInfo(opt), where

opt = {
  user: username, //opt, defaults to init user
};

Get Loved Tracks

Last.FM Documentation

user_getLovedTracks(opt), where

opt = {
  user: username, //opt
  limit: limit, //opt, default is 50
  page: page, //opt, default is 1
};

Get Personal Tags

Last.FM Documentation

user_getPersonalTags(opt), where

opt = {
  user: username, //opt
  tag: tag, //req
  taggingtype: artist | album | track, //req
  limit: limit, //opt, default is 50
  page: page, //opt, default is 1
};

Get Recent Tracks

Last.FM Documentation

user_getRecentTracks(opt), where

opt = {
  user: username, //opt
  from: startTime, //opt
  extended: 0 | 1, //opt
  to: endTime, //opt
  limit: limit, //opt, default is 50
  page: page, //opt, default is 1
};

Get Top Albums

Last.FM Documentation

user_getTopAlbums(opt), where

    opt = {
        user: username, //opt
        period: overall|7day|1month|3month|6month|12month, //opt, default is overall
        limit: limit, //opt, default is 50
        page: page, //opt, default is 1
    }

Get Top Artists

Last.FM Documentation

user_getTopArtists(opt), where

    opt = {
        user: username, //opt
        period: overall|7day|1month|3month|6month|12month, //opt, default is overall
        limit: limit, //opt, default is 50
        page: page, //opt, default is 1
    }

Get Top Tags

Last.FM Documentation

user_getTopTags(opt), where

opt = {
  user: username, //opt
  limit: limit, //opt, default is 50
};

Get Top Tracks

Last.FM Documentation

user_getTopTracks(opt), where

    opt = {
        user: username, //opt
        period: overall|7day|1month|3month|6month|12month, //opt, default is overall
        limit: limit, //opt, default is 50
        page: page, //opt, default is 1
    }

Get Weekly Album Chart

Last.FM Documentation

user_getWeeklyAlbumChart(opt), where

opt = {
  user: username, //opt
  from: startdate, //opt, default is overall
  to: enddate, //opt, default is 50
};

Get Weekly Artist Chart

Last.FM Documentation

user_getWeeklyArtistChart(opt), where

opt = {
  user: username, //opt
  from: startdate, //opt, default is overall
  to: enddate, //opt, default is 50
};

Get Weekly Chart List

Last.FM Documentation

user_getWeeklyChartList(opt), where

opt = {
  user: username, //opt
};

Get Weekly Track Chart

Last.FM Documentation

user_getWeeklyTrackChart(opt), where

opt = {
  user: username, //opt
  from: startdate, //opt, default is overall
  to: enddate, //opt, default is 50
};