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,
album: album,
tags: tags,
};
*Requires Authentication
Get Info
Last.FM Documentation
album_getInfo(opt)
, where
opt = {
artist: artist,
album: album,
mbid: mbid,
lang: lang,
username: username,
};
Get Tags
Last.FM Documentation
album_getTags(opt)
, where
opt = {
artist: artist,
album: album,
username: username,
mbid: mbid,
};
Get Top Tags
Last.FM Documentation
album_getTopTags(opt)
, where
opt = {
artist: artist,
album: album,
mbid: mbid,
};
Remove Tag*
Last.FM Documentation
album_removeTag(opt)
, where
opt = {
artist: artist,
album: album,
tag: tag,
};
*Requires Authentication
Album Search
Last.FM Documentation
album_getTopTags(opt)
, where
opt = {
album: album,
limit: limit,
page: page,
};
Artist
Examples
Add Tags*
Last.FM Documentation
artist_addTags(opt)
, where
opt = {
artist: artist
tags: tags,
}
*Requires Authentication
Get Correction
Last.FM Documentation
artist_getCorrection(opt)
, where
opt = {
artist: artist,
};
Get Info
Last.FM Documentation
artist_getInfo(opt)
, where
opt = {
artist: artist,
mbid: mbid,
username: username,
};
Get Similar
Last.FM Documentation
artist_getSimilar(opt)
, where
opt = {
artist: artist,
mbid: mbid,
limit: limit,
};
Get Tags
Last.FM Documentation
artist_getTags(opt)
, where
opt = {
artist: artist,
user: username,
mbid: mbid,
};
Get Top Albums
Last.FM Documentation
artist_getTopAlbums(opt)
, where
opt = {
artist: artist,
mbid: mbid,
page: page,
limit: limit,
};
Get Top Tags
Last.FM Documentation
artist_getTopTags(opt)
, where
opt = {
artist: artist,
mbid: mbid,
};
Get Top Tracks
Last.FM Documentation
artist_getTopTracks(opt)
, where
opt = {
artist: artist,
mbid: mbid,
page: page,
limit: limit,
};
Remove Tag*
Last.FM Documentation
artist_removeTag(opt)
, where
opt = {
artist: artist
tag: tag,
}
*Requires Authentication
Search
Last.FM Documentation
artist_search(opt)
, where
opt = {
artist: artist,
page: page,
limit: limit,
};
Chart Methods
Examples
Get Top Artists
Last.FM Documentation
chart_getTopArtists(opt)
, where
opt = {
page: page,
limit: limit,
};
Get Top Tags
Last.FM Documentation
chart_getTopTags(opt)
, where
opt = {
page: page,
limit: limit,
};
Get Top Tracks
Last.FM Documentation
chart_getTopTracks(opt)
, where
opt = {
page: page,
limit: limit,
};
Geo Methods
Examples
Get Top Artists
Last.FM Documentation
geo_getTopArtists(opt)
, where
opt = {
country: country,
page: page,
limit: limit,
};
Get Top Tracks
Last.FM Documentation
geo_getTopTracks(opt)
, where
opt = {
country: country,
page: page,
limit: limit,
};
Library Methods
Examples
Get Artists
Last.FM Documentation
library_getArtists(opt)
, where
opt = {
user: username,
page: page,
limit: limit,
};
Tag Methods
Examples
Get Info
Last.FM Documentation
tag_getInfo(opt)
, where
opt = {
tag: tag,
lang: lang,
};
Get Similar
Last.FM Documentation
tag_getSimilar(opt)
, where
opt = {
tag: tag,
};
Get Top Albums
Last.FM Documentation
tag_getTopAlbums(opt)
, where
opt = {
tag: tag,
limit: limit,
page: page,
};
Get Top Artists
Last.FM Documentation
tag_getTopArtists(opt)
, where
opt = {
tag: tag,
limit: limit,
page: page,
};
Get Top Tags
Last.FM Documentation
tag_getTopTags(opt)
, where
opt = {};
Get Top Tracks
Last.FM Documentation
tag_getTopTracks(opt)
, where
opt = {
tag: tag,
limit: limit,
page: page,
};
Get Weekly Chart List
Last.FM Documentation
tag_getWeeklyChartList(opt)
, where
opt = {
tag: tag,
};
Track Methods
Examples
Add Tags*
Last.FM Documentation
track_addTags(opt)
, where
opt = {
artist: artist,
track: track,
tags: tags,
};
*Requires Authentication
Get Correction
Last.FM Documentation
track_getCorrection(opt)
, where
opt = {
artist: artist,
track: track,
};
Get Info
Last.FM Documentation
track_getInfo(opt)
, where
opt = {
artist: artist,
track: track,
mbid: mbid,
username: username,
};
Get Similar
Last.FM Documentation
track_getSimilar(opt)
, where
opt = {
artist: artist,
track: track,
mbid: mbid,
limit: limit,
};
Get Tags
Last.FM Documentation
track_getTags(opt)
, where
opt = {
artist: artist,
track: track,
username: username,
mbid: mbid,
};
Get Top Tags
Last.FM Documentation
track_getTopTags(opt)
, where
opt = {
artist: artist,
track: track,
mbid: mbid,
};
Love Track*
Last.FM Documentation
track_love(opt)
, where
opt = {
artist: artist,
track: track,
};
*Requires Authentication
Remove Tag*
Last.FM Documentation
track_removeTag(opt)
, where
opt = {
artist: artist,
track: track,
tag: tag,
};
*Requires Authentication
Scrobble*
Last.FM Documentation
track_scrobble(opt)
, where
opt = {
artist: artist[i],
track: track[i],
timestamp: timestamp[i],
album: album[i],
context: context[i],
streamId: streamId[i],
chosenByUser: chosenByUser[i],
trackNumber: trackNumber[i],
mbid: mbid[i],
albumArtist: albumArtist[i],
duration: duration[i],
};
*Requires Authentication
Search
Last.FM Documentation
track_search(opt)
, where
opt = {
track: track,
artist: artist,
limit: limit,
page: page,
};
Unlove*
Last.FM Documentation
track_unlove(opt)
, where
opt = {
track: track,
artist: artist,
};
*Requires Authentication
Update Now Playing*
Last.FM Documentation
track_updateNowPlaying(opt)
, where
opt = {
artist: artist,
track: track,
album: album,
context: context
trackNumber: trackNumber,
mbid: mbid,
albumArtist: albumArtist,
duration: duration,
}
*Requires Authentication
User Methods
Examples
Get Artist Tracks
Last.FM Documentation
user_getArtistTracks(opt)
, where
opt = {
user: username,
artist: artist,
startTimestamp: startTimestamp,
page: page,
endTimestamp: endTimestamp,
};
Get Friends
Last.FM Documentation
user_getFriends(opt)
, where
opt = {
user: username,
recentTracks: recentTracks,
limit: limit,
page: page,
};
Get Info
Last.FM Documentation
user_getInfo(opt)
, where
opt = {
user: username,
};
Get Loved Tracks
Last.FM Documentation
user_getLovedTracks(opt)
, where
opt = {
user: username,
limit: limit,
page: page,
};
Get Personal Tags
Last.FM Documentation
user_getPersonalTags(opt)
, where
opt = {
user: username,
tag: tag,
taggingtype: artist | album | track,
limit: limit,
page: page,
};
Get Recent Tracks
Last.FM Documentation
user_getRecentTracks(opt)
, where
opt = {
user: username,
from: startTime,
extended: 0 | 1,
to: endTime,
limit: limit,
page: page,
};
Get Top Albums
Last.FM Documentation
user_getTopAlbums(opt)
, where
opt = {
user: username,
period: overall|7day|1month|3month|6month|12month,
limit: limit,
page: page,
}
Get Top Artists
Last.FM Documentation
user_getTopArtists(opt)
, where
opt = {
user: username,
period: overall|7day|1month|3month|6month|12month,
limit: limit,
page: page,
}
Get Top Tags
Last.FM Documentation
user_getTopTags(opt)
, where
opt = {
user: username,
limit: limit,
};
Get Top Tracks
Last.FM Documentation
user_getTopTracks(opt)
, where
opt = {
user: username,
period: overall|7day|1month|3month|6month|12month,
limit: limit,
page: page,
}
Get Weekly Album Chart
Last.FM Documentation
user_getWeeklyAlbumChart(opt)
, where
opt = {
user: username,
from: startdate,
to: enddate,
};
Get Weekly Artist Chart
Last.FM Documentation
user_getWeeklyArtistChart(opt)
, where
opt = {
user: username,
from: startdate,
to: enddate,
};
Get Weekly Chart List
Last.FM Documentation
user_getWeeklyChartList(opt)
, where
opt = {
user: username,
};
Get Weekly Track Chart
Last.FM Documentation
user_getWeeklyTrackChart(opt)
, where
opt = {
user: username,
from: startdate,
to: enddate,
};