Skip to content

TrackStructure

Defined in: src/structures/track.ts:33

new TrackStructure(client: FMClient): TrackStructure;

Defined in: src/structures/track.ts:36

FMClient

TrackStructure

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.

TrackGetSimilarOptions

The options. See TrackGetSimilarOptions.

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 }
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(options: TrackLoveOptions): Promise<LoveResponse>;

Defined in: src/structures/track.ts:310

Love a track for a user profile.

TrackLoveOptions

The options. See TrackLoveOptions.

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 }
const res = await fm.track.love({
sk: "SESSION_KEY",
artist: "Michael Jackson",
track: "Billie Jean",
});
if (res.success) {
console.log("Track loved");
}

scrobble(options: ScrobbleOptions): Promise<ScrobbleResponse>;

Defined in: src/structures/track.ts:61

Used to add a track-play to a user’s profile.

ScrobbleOptions

The options. See ScrobbleOptions.

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 }
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(options: ScrobbleBatchOptions): Promise<ScrobbleBatchResponse>;

Defined in: src/structures/track.ts:117

Used to add multiple track-plays to a user’s profile.

ScrobbleBatchOptions

The options. See ScrobbleBatchOptions.

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 }
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(options: TrackSearchOptions): Promise<TrackSearchResponse>;

Defined in: src/structures/track.ts:405

Search for a track by track name. Returns track matches sorted by relevance.

TrackSearchOptions

The options. See TrackSearchOptions.

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 }
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(options: TrackUnLoveOptions): Promise<UnLoveResponse>;

Defined in: src/structures/track.ts:358

UnLove a track for a user profile.

TrackUnLoveOptions

The options. See TrackUnLoveOptions.

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 }
const res = await fm.track.unlove({
sk: "SESSION_KEY",
artist: "Michael Jackson",
track: "Billie Jean",
});
if (res.success) {
console.log("Track unloved");
}

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.

ExtendedBaseOptions

The options. See UpdateNowPlayingOptions.

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 }
const res = await fm.track.updateNowPlaying({
sk: "SESSION_KEY",
artist: "Michael Jackson",
track: "Billie Jean",
});
if (res.success) {
console.log("Now playing updated");
}