TrackStructure
Defined in: src/structures/track.ts:33
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TrackStructure(client: FMClient): TrackStructure;Defined in: src/structures/track.ts:36
Parameters
Section titled “Parameters”client
Section titled “client”Returns
Section titled “Returns”TrackStructure
Methods
Section titled “Methods”getSimilar()
Section titled “getSimilar()”getSimilar(options: TrackGetSimilarOptions): Promise<SimilarTrackResponse>;Defined in: src/structures/track.ts:227
Get the similar tracks for this track on Last.fm, based on listening data.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See TrackGetSimilarOptions.
Returns
Section titled “Returns”Promise<SimilarTrackResponse>
A promise that resolves to the API response object.
- Success:
{ success: true, similarTracks: Array, trackName: string, artistName: string } - Failure:
{ success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | ErrorCodes.NO_SIMILAR_TRACKS | number | string, errorMsg: string }
Example
Section titled “Example”const res = await fm.track.getSimilar({ artist: "Michael Jackson", track: "Billie Jean", limit: 5,});
if (res.success) { console.log(`Top similar track: ${res.similarTracks[0].name}`);}love()
Section titled “love()”love(options: TrackLoveOptions): Promise<LoveResponse>;Defined in: src/structures/track.ts:310
Love a track for a user profile.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See TrackLoveOptions.
Returns
Section titled “Returns”Promise<LoveResponse>
A promise that resolves to the API response object.
- Success:
{ success: true } - Failure:
{ success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | number | string, errorMsg: string }
Example
Section titled “Example”const res = await fm.track.love({ sk: "SESSION_KEY", artist: "Michael Jackson", track: "Billie Jean",});
if (res.success) { console.log("Track loved");}scrobble()
Section titled “scrobble()”scrobble(options: ScrobbleOptions): Promise<ScrobbleResponse>;Defined in: src/structures/track.ts:61
Used to add a track-play to a user’s profile.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See ScrobbleOptions.
Returns
Section titled “Returns”Promise<ScrobbleResponse>
A promise that resolves to the API response object.
- Success:
{ success: true } - Failure:
{ success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | number | string, errorMsg: string }
Example
Section titled “Example”const res = await fm.track.scrobble({ sk: "SESSION_KEY", artist: "Michael Jackson", track: "Billie Jean", timestamp: Math.floor(Date.now() / 1000),});
if (res.success) { console.log("Track scrobbled successfully");}scrobbleBatch()
Section titled “scrobbleBatch()”scrobbleBatch(options: ScrobbleBatchOptions): Promise<ScrobbleBatchResponse>;Defined in: src/structures/track.ts:117
Used to add multiple track-plays to a user’s profile.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See ScrobbleBatchOptions.
Returns
Section titled “Returns”Promise<ScrobbleBatchResponse>
A promise that resolves to the API response object.
- Success:
{ success: true, scrobbledCount: number } - Failure:
{ success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | number | string, errorMsg: string, scrobbledCount: number }
Example
Section titled “Example”const res = await fm.track.scrobbleBatch({ sk: "SESSION_KEY", tracks: [ { artist: "Michael Jackson", track: "Billie Jean", timestamp: 1600000000 }, { artist: "Daft Punk", track: "One More Time", timestamp: 1600000300 }, ],});
if (res.success) { console.log(`Scrobbled ${res.scrobbledCount} tracks.`);}search()
Section titled “search()”search(options: TrackSearchOptions): Promise<TrackSearchResponse>;Defined in: src/structures/track.ts:405
Search for a track by track name. Returns track matches sorted by relevance.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See TrackSearchOptions.
Returns
Section titled “Returns”Promise<TrackSearchResponse>
A promise that resolves to the API response object.
- Success:
{ success: true, tracks: Array, totalResultsOnLastFm: number | null } - Failure:
{ success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | ErrorCodes.NO_TRACK_MATCHES | number | string, errorMsg: string }
Example
Section titled “Example”const res = await fm.track.search({ track: "Billie Jean", limit: 5,});
if (res.success) { console.log(`First result: ${res.tracks[0].name} by ${res.tracks[0].artist}`);}unlove()
Section titled “unlove()”unlove(options: TrackUnLoveOptions): Promise<UnLoveResponse>;Defined in: src/structures/track.ts:358
UnLove a track for a user profile.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See TrackUnLoveOptions.
Returns
Section titled “Returns”Promise<UnLoveResponse>
A promise that resolves to the API response object.
- Success:
{ success: true } - Failure:
{ success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | number | string, errorMsg: string }
Example
Section titled “Example”const res = await fm.track.unlove({ sk: "SESSION_KEY", artist: "Michael Jackson", track: "Billie Jean",});
if (res.success) { console.log("Track unloved");}updateNowPlaying()
Section titled “updateNowPlaying()”updateNowPlaying(options: ExtendedBaseOptions): Promise<UpdateNowPlayingResponse>;Defined in: src/structures/track.ts:178
Used to notify Last.fm that a user has started listening to a track.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See UpdateNowPlayingOptions.
Returns
Section titled “Returns”Promise<UpdateNowPlayingResponse>
A promise that resolves to the API response object.
- Success:
{ success: true } - Failure:
{ success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | number | string, errorMsg: string }
Example
Section titled “Example”const res = await fm.track.updateNowPlaying({ sk: "SESSION_KEY", artist: "Michael Jackson", track: "Billie Jean",});
if (res.success) { console.log("Now playing updated");}