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({
apiKey: config.key,
apiSecret: config.secret,
username: config.username
});
If a method requires writing to an account, then you also need password
var lfm = new lastfm({
apiKey: config.key,
apiSecret: config.secret,
username: config.username,
password: config.password
});
After this, you can use any of the methods
- Authentication Methods
- Album Methods
- Artist Methods
- Geo Methods
- Library Methods
- Tag Methods
- Track Methods
- User Methods
lastfm.auth_getMobileSession(function(res) {
if (res.success) {
lastfm.album_addTags({
artist: 'Oh Pep!',
album: 'Living',
tags: 'peppy,folk,music',
callback(res) {
printRes(res);
}
});
}
else{
printError(res);
}
});
is the same as
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
A username and password is required
auth_getMobileSession(callback);
where callback is a function which either returns
{
success: true,
key: 'XXX'
}
or
{
success: false,
error: [lastFMError]
}
album_addTags(opt)
, where
opt = {
artist: artist, //req
album: album, //req
tags: tags, //req, max: 10, comma separated list
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
album_getInfo(opt)
, where
opt = {
artist: artist, //req unless mbid
album: album, //req unless mbid
mbid: mbid, //opt
lang: lang, //opt
username: username, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
album_getTags(opt)
, where
opt = {
artist: artist, //req unless mbid
album: album, //req unless mbid
username: username, //req
mbid: mbid, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
album_getTopTags(opt)
, where
opt = {
artist: artist, //req unless mbid
album: album, //req unless mbid
mbid: mbid, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
album_removeTag(opt)
, where
opt = {
artist: artist, //req
album: album, //req
tag: tag, //req, single tag to remove
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
album_getTopTags(opt)
, where
opt = {
album: album, //req
limit: limit, //opt, defaults to 30
page: page, //opt, defaults to 1
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
artist_addTags(opt)
, where
opt = {
artist: artist //req
tags: tags, //req, max 10, comma separated
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
artist_getCorrection(opt)
, where
opt = {
artist: artist, //req
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
artist_getInfo(opt)
, where
opt = {
artist: artist, //req unless mbid
mbid: mbid, //opt
username: username, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
artist_getSimilar(opt)
, where
opt = {
artist: artist, //req unless mbid
mbid: mbid, //opt
limit: limit, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
artist_getTags(opt)
, where
opt = {
artist: artist, //req unless mbid
user: username, //req
mbid: mbid, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
artist_getTopTags(opt)
, where
opt = {
artist: artist, //req unless mbid
mbid: mbid, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
artist_removeTag(opt)
, where
opt = {
artist: artist //req
tag: tag, //req, 1 tag to be removed
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
artist_search(opt)
, where
opt = {
artist: artist, //req unless mbid
page: page, //opt, default is 1
limit: limit, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
chart_getTopArtists(opt)
, where
opt = {
page: page, //opt, default is 1
limit: limit, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
chart_getTopTags(opt)
, where
opt = {
page: page, //opt, default is 1
limit: limit, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
chart_getTopTracks(opt)
, where
opt = {
page: page, //opt, default is 1
limit: limit, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
geo_getTopArtists(opt)
, where
opt = {
country: country, //req, ISO 3166-1 format
page: page, //opt, default is 1
limit: limit, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
geo_getTopTracks(opt)
, where
opt = {
country: country, //req, ISO 3166-1 format
page: page, //opt, default is 1
limit: limit, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
library_getArtists(opt)
, where
opt = {
user: username, //req
page: page, //opt, default is 1
limit: limit, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
tag_getInfo(opt)
, where
opt = {
tag: tag, //req
lang: lang, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
tag_getSimilar(opt)
, where
opt = {
tag: tag, //req
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
tag_getTopAlbums(opt)
, where
opt = {
tag: tag, //req
limit: limit, //opt, default is 50
page: page, //opt, default is 1
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
tag_getTopArtists(opt)
, where
opt = {
tag: tag, //req
limit: limit, //opt, default is 50
page: page, //opt, default is 1
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
tag_getTopTags(opt)
, where
opt = {
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
tag_getTopTracks(opt)
, where
opt = {
tag: tag, //req
limit: limit, //opt, defaults to 50
page: page, //opt, defaults to 1
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
tag_getWeeklyChartList(opt)
, where
opt = {
tag: tag, //req
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
track_addTags(opt)
, where
opt = {
artist: artist, //req
track: track, //req
tags: tags, //req, max: 10
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
track_getCorrection(opt)
, where
opt = {
artist: artist, //req
track: track, //req
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
track_getInfo(opt)
, where
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
mbid: mbid, //opt
username: username, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
track_getSimilar(opt)
, where
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
mbid: mbid, //opt
limit: limit, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
track_getTags(opt)
, where
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
username: username, //req
mbid: mbid, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
track_getTopTags(opt)
, where
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
mbid: mbid, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
track_love(opt)
, where
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
track_removeTag(opt)
, where
opt = {
artist: artist, //req
track: track, //req
tag: tag, //req, single tag to remove
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
track_search(opt)
, where
opt = {
track: track, //req
artist: artist, //opt
limit: limit, //opt, defaults to 30
page: page, //opt, defaults to 1
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
track_unlove(opt)
, where
opt = {
track: track, //req
artist: artist, //req
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
*Requires Authentication
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
user_getInfo(opt)
, where
opt = {
user: username, //opt, defaults to init user
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
user_getLovedTracks(opt)
, where
opt = {
user: username, //opt
limit: limit, //opt, default is 50
page: page, //opt, default is 1
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
user_getTopTags(opt)
, where
opt = {
user: username, //opt
limit: limit, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
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
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
user_getWeeklyAlbumChart(opt)
, where
opt = {
user: username, //opt
from: startdate, //opt, default is overall
to: enddate, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
user_getWeeklyArtistChart(opt)
, where
opt = {
user: username, //opt
from: startdate, //opt, default is overall
to: enddate, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
user_getWeeklyChartList(opt)
, where
opt = {
user: username, //opt
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error
user_getWeeklyTrackChart(opt)
, where
opt = {
user: username, //opt
from: startdate, //opt, default is overall
to: enddate, //opt, default is 50
callback(res){}
}
and callback is a function which receives a single object, containing the Last.FM response and success: false
if there was an error