Skip to content

UserStructure

Defined in: src/structures/user.ts:27

new UserStructure(client: FMClient): UserStructure;

Defined in: src/structures/user.ts:30

FMClient

UserStructure

getInfo(user: string): Promise<UserInfoResponse>;

Defined in: src/structures/user.ts:50

Get information about a user profile.

string

The user to fetch info for.

Promise<UserInfoResponse>

A promise that resolves to the API response object.

  • Success: { success: true, user: object }
  • Failure: { success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | ErrorCodes.NO_USER_DATA | number | string, errorMsg: string }
const res = await fm.user.getInfo("USERNAME");
if (res.success) {
console.log(`User ${res.user.name} has ${res.user.scrobbles} total scrobbles.`);
}

getLovedTracks(options: UserGetLovedTracksOptions): Promise<UserLovedTracksResponse>;

Defined in: src/structures/user.ts:108

Get tracks loved by a user.

UserGetLovedTracksOptions

The options. See UserGetLovedTracksOptions.

Promise<UserLovedTracksResponse>

A promise that resolves to the API response object.

  • Success: { success: true, lovedTracks: Array, totalLoved: number | null }
  • Failure: { success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | ErrorCodes.USER_NO_LOVED_TRACKS | number | string, errorMsg: string }
const res = await fm.user.getLovedTracks({
user: "USERNAME",
limit: 5,
});
if (res.success) {
console.log(`First loved track: ${res.lovedTracks[0].name}`);
}

getNowPlaying(user: string): Promise<UserNowPlayingResponse>;

Defined in: src/structures/user.ts:515

Get the now playing track of this user.

string

The last.fm username to fetch now playing track of.

Promise<UserNowPlayingResponse>

A promise that resolves to the API response object.

  • Success: { success: true, track: object }
  • Failure: { success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | ErrorCodes.NOT_PLAYING | ErrorCodes.TRACK_UNAVAILABLE | number | string, errorMsg: string }
const res = await fm.user.getNowPlaying("USERNAME");
if (res.success) {
console.log(`Listening to: ${res.track.name} by ${res.track.artist.name}`);
}

getRecentTracks(options: UserGetLovedTracksOptions): Promise<UserRecentTracksResponse>;

Defined in: src/structures/user.ts:187

Get a list of the recent tracks listened to by this user.

UserGetLovedTracksOptions

The options. See UserGetRecentTracksOptions.

Promise<UserRecentTracksResponse>

A promise that resolves to the API response object.

  • Success: { success: true, recentTracks: Array, nowPlaying: boolean }
  • Failure: { success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | ErrorCodes.USER_NO_RECENT_TRACKS | number | string, errorMsg: string }
const res = await fm.user.getRecentTracks({
user: "USERNAME",
limit: 10,
});
if (res.success) {
console.log(`Most recent track: ${res.recentTracks[0].name}`);
}

getTopAlbums(options: UserGetTopTracksOptions): Promise<UserTopAlbumsResponse>;

Defined in: src/structures/user.ts:435

Get the top albums listened to by a user. You can stipulate a time period. Sends the overall chart by default.

UserGetTopTracksOptions

The options. See UserGetTopAlbumsOptions.

Promise<UserTopAlbumsResponse>

A promise that resolves to the API response object.

  • Success: { success: true, topAlbums: Array, uniqueAlbums: number | null }
  • Failure: { success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | ErrorCodes.USER_NO_TOP_ALBUMS | number | string, errorMsg: string }
const res = await fm.user.getTopAlbums({
user: "USERNAME",
limit: 10,
});
if (res.success) {
console.log(`Top album: ${res.topAlbums[0].name}`);
}

getTopArtists(options: UserGetTopTracksOptions): Promise<UserTopArtistsResponse>;

Defined in: src/structures/user.ts:356

Get the top artists listened to by a user. You can stipulate a time period. Sends the overall chart by default.

UserGetTopTracksOptions

The options. See UserGetTopArtistsOptions.

Promise<UserTopArtistsResponse>

A promise that resolves to the API response object.

  • Success: { success: true, topArtists: Array, uniqueArtists: number | null }
  • Failure: { success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | ErrorCodes.USER_NO_TOP_ARTISTS | number | string, errorMsg: string }
const res = await fm.user.getTopArtists({
user: "USERNAME",
limit: 10,
});
if (res.success) {
console.log(`Top artist: ${res.topArtists[0].name}`);
}

getTopTracks(options: UserGetTopTracksOptions): Promise<UserTopTracksResponse>;

Defined in: src/structures/user.ts:271

Get the top tracks listened to by a user. You can stipulate a time period. Sends the overall chart by default.

UserGetTopTracksOptions

The options. See UserGetTopTracksOptions.

Promise<UserTopTracksResponse>

A promise that resolves to the API response object.

  • Success: { success: true, topTracks: Array, uniqueTracks: number | null }
  • Failure: { success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | ErrorCodes.USER_NO_TOP_TRACKS | number | string, errorMsg: string }
const res = await fm.user.getTopTracks({
user: "USERNAME",
limit: 10,
period: "7day",
});
if (res.success) {
console.log(`Top track this week: ${res.topTracks[0].name}`);
}