A complete last.fm API for Node.JS
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:
``ts`
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
`ts`
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
`ts
import LastFM from 'lastfm-njs';
const client = new LastFM(...)
`
or require with
`ts
const LastFM = require("lastfm-njs");
const client = new LastFM.default(...)
`
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
#### All methods use promises
`ts`
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();
which either returns
`ts`
{
success: true,
key: 'XXX'
}
or
`ts`
{
success: false,
error: [lastFMError]
}
#### Add Tags\*
album_addTags(opt), where
`ts`
opt = {
artist: artist, //req
album: album, //req
tags: tags, //req, max: 10, comma separated list
};
_\*Requires Authentication_
#### Get Info
album_getInfo(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
album: album, //req unless mbid
mbid: mbid, //opt
lang: lang, //opt
username: username, //opt
};
#### Get Tags
album_getTags(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
album: album, //req unless mbid
username: username, //req
mbid: mbid, //opt
};
#### Get Top Tags
album_getTopTags(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
album: album, //req unless mbid
mbid: mbid, //opt
};
#### Remove Tag\*
album_removeTag(opt), where
`ts`
opt = {
artist: artist, //req
album: album, //req
tag: tag, //req, single tag to remove
};
_\*Requires Authentication_
#### Album Search
album_getTopTags(opt), where
`ts`
opt = {
album: album, //req
limit: limit, //opt, defaults to 30
page: page, //opt, defaults to 1
};
#### Add Tags\*
artist_addTags(opt), where
`ts`
opt = {
artist: artist //req
tags: tags, //req, max 10, comma separated
}
_\*Requires Authentication_
#### Get Correction
artist_getCorrection(opt), where
`ts`
opt = {
artist: artist, //req
};
#### Get Info
artist_getInfo(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
mbid: mbid, //opt
username: username, //opt
};
#### Get Similar
artist_getSimilar(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
mbid: mbid, //opt
limit: limit, //opt
};
#### Get Tags
artist_getTags(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
user: username, //req
mbid: mbid, //opt
};
#### Get Top Albums
artist_getTopAlbums(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
mbid: mbid, //opt
page: page, //opt, default is 50
limit: limit, //opt, default is 1
};
#### Get Top Tags
artist_getTopTags(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
mbid: mbid, //opt
};
#### Get Top Tracks
artist_getTopTracks(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
mbid: mbid, //opt
page: page, //opt, default is 1
limit: limit, //opt, default is 50
};
#### Remove Tag\*
artist_removeTag(opt), where
`ts`
opt = {
artist: artist //req
tag: tag, //req, 1 tag to be removed
}
_\*Requires Authentication_
#### Search
artist_search(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
page: page, //opt, default is 1
limit: limit, //opt, default is 50
};
#### Get Top Artists
chart_getTopArtists(opt), where
`ts`
opt = {
page: page, //opt, default is 1
limit: limit, //opt, default is 50
};
#### Get Top Tags
chart_getTopTags(opt), where
`ts`
opt = {
page: page, //opt, default is 1
limit: limit, //opt, default is 50
};
#### Get Top Tracks
chart_getTopTracks(opt), where
`ts`
opt = {
page: page, //opt, default is 1
limit: limit, //opt, default is 50
};
#### Get Top Artists
geo_getTopArtists(opt), where
`ts`
opt = {
country: country, //req, ISO 3166-1 format
page: page, //opt, default is 1
limit: limit, //opt, default is 50
};
#### Get Top Tracks
geo_getTopTracks(opt), where
`ts`
opt = {
country: country, //req, ISO 3166-1 format
page: page, //opt, default is 1
limit: limit, //opt, default is 50
};
#### Get Artists
library_getArtists(opt), where
`ts`
opt = {
user: username, //req
page: page, //opt, default is 1
limit: limit, //opt, default is 50
};
#### Get Info
tag_getInfo(opt), where
`ts`
opt = {
tag: tag, //req
lang: lang, //opt
};
#### Get Similar
tag_getSimilar(opt), where
`ts`
opt = {
tag: tag, //req
};
#### Get Top Albums
tag_getTopAlbums(opt), where
`ts`
opt = {
tag: tag, //req
limit: limit, //opt, default is 50
page: page, //opt, default is 1
};
#### Get Top Artists
tag_getTopArtists(opt), where
`ts`
opt = {
tag: tag, //req
limit: limit, //opt, default is 50
page: page, //opt, default is 1
};
#### Get Top Tags
tag_getTopTags(opt), where
`ts`
opt = {};
#### Get Top Tracks
tag_getTopTracks(opt), where
`ts`
opt = {
tag: tag, //req
limit: limit, //opt, defaults to 50
page: page, //opt, defaults to 1
};
#### Get Weekly Chart List
tag_getWeeklyChartList(opt), where
`ts`
opt = {
tag: tag, //req
};
#### Add Tags\*
track_addTags(opt), where
`ts`
opt = {
artist: artist, //req
track: track, //req
tags: tags, //req, max: 10
};
_\*Requires Authentication_
#### Get Correction
track_getCorrection(opt), where
`ts`
opt = {
artist: artist, //req
track: track, //req
};
#### Get Info
track_getInfo(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
mbid: mbid, //opt
username: username, //opt
};
#### Get Similar
track_getSimilar(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
mbid: mbid, //opt
limit: limit, //opt
};
#### Get Tags
track_getTags(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
username: username, //req
mbid: mbid, //opt
};
#### Get Top Tags
track_getTopTags(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
mbid: mbid, //opt
};
#### Love Track\*
track_love(opt), where
`ts`
opt = {
artist: artist, //req unless mbid
track: track, //req unless mbid
};
_\*Requires Authentication_
#### Remove Tag\*
track_removeTag(opt), where
`ts`
opt = {
artist: artist, //req
track: track, //req
tag: tag, //req, single tag to remove
};
_\*Requires Authentication_
#### Scrobble\*
track_scrobble(opt), where
`ts`
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
track_search(opt), where
`ts`
opt = {
track: track, //req
artist: artist, //opt
limit: limit, //opt, defaults to 30
page: page, //opt, defaults to 1
};
#### Unlove\*
track_unlove(opt), where
`ts`
opt = {
track: track, //req
artist: artist, //req
};
_\*Requires Authentication_
#### Update Now Playing\*
track_updateNowPlaying(opt), where
`ts`
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_
#### Get Artist Tracks
user_getArtistTracks(opt), where
`ts`
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
user_getFriends(opt), where
`ts`
opt = {
user: username, //opt
recentTracks: recentTracks, //opt, true|false
limit: limit, //opt defaults to 50
page: page, //opt, default is 1
};
#### Get Info
user_getInfo(opt), where
`ts`
opt = {
user: username, //opt, defaults to init user
};
#### Get Loved Tracks
user_getLovedTracks(opt), where
`ts`
opt = {
user: username, //opt
limit: limit, //opt, default is 50
page: page, //opt, default is 1
};
#### Get Personal Tags
user_getPersonalTags(opt), where
`ts`
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
user_getRecentTracks(opt), where
`ts`
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
user_getTopAlbums(opt), where
`ts`
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
user_getTopArtists(opt), where
`ts`
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
user_getTopTags(opt), where
`ts`
opt = {
user: username, //opt
limit: limit, //opt, default is 50
};
#### Get Top Tracks
user_getTopTracks(opt), where
`ts`
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
user_getWeeklyAlbumChart(opt), where
`ts`
opt = {
user: username, //opt
from: startdate, //opt, default is overall
to: enddate, //opt, default is 50
};
#### Get Weekly Artist Chart
user_getWeeklyArtistChart(opt), where
`ts`
opt = {
user: username, //opt
from: startdate, //opt, default is overall
to: enddate, //opt, default is 50
};
#### Get Weekly Chart List
user_getWeeklyChartList(opt), where
`ts`
opt = {
user: username, //opt
};
#### Get Weekly Track Chart
user_getWeeklyTrackChart(opt), where
`ts``
opt = {
user: username, //opt
from: startdate, //opt, default is overall
to: enddate, //opt, default is 50
};