UserStructure
Defined in: src/structures/user.ts:27
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new UserStructure(client: FMClient): UserStructure;Defined in: src/structures/user.ts:30
Parameters
Section titled “Parameters”client
Section titled “client”Returns
Section titled “Returns”UserStructure
Methods
Section titled “Methods”getInfo()
Section titled “getInfo()”getInfo(user: string): Promise<UserInfoResponse>;Defined in: src/structures/user.ts:50
Get information about a user profile.
Parameters
Section titled “Parameters”string
The user to fetch info for.
Returns
Section titled “Returns”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 }
Example
Section titled “Example”const res = await fm.user.getInfo("USERNAME");
if (res.success) { console.log(`User ${res.user.name} has ${res.user.scrobbles} total scrobbles.`);}getLovedTracks()
Section titled “getLovedTracks()”getLovedTracks(options: UserGetLovedTracksOptions): Promise<UserLovedTracksResponse>;Defined in: src/structures/user.ts:108
Get tracks loved by a user.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See UserGetLovedTracksOptions.
Returns
Section titled “Returns”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 }
Example
Section titled “Example”const res = await fm.user.getLovedTracks({ user: "USERNAME", limit: 5,});
if (res.success) { console.log(`First loved track: ${res.lovedTracks[0].name}`);}getNowPlaying()
Section titled “getNowPlaying()”getNowPlaying(user: string): Promise<UserNowPlayingResponse>;Defined in: src/structures/user.ts:515
Get the now playing track of this user.
Parameters
Section titled “Parameters”string
The last.fm username to fetch now playing track of.
Returns
Section titled “Returns”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 }
Example
Section titled “Example”const res = await fm.user.getNowPlaying("USERNAME");
if (res.success) { console.log(`Listening to: ${res.track.name} by ${res.track.artist.name}`);}getRecentTracks()
Section titled “getRecentTracks()”getRecentTracks(options: UserGetLovedTracksOptions): Promise<UserRecentTracksResponse>;Defined in: src/structures/user.ts:187
Get a list of the recent tracks listened to by this user.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See UserGetRecentTracksOptions.
Returns
Section titled “Returns”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 }
Example
Section titled “Example”const res = await fm.user.getRecentTracks({ user: "USERNAME", limit: 10,});
if (res.success) { console.log(`Most recent track: ${res.recentTracks[0].name}`);}getTopAlbums()
Section titled “getTopAlbums()”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.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See UserGetTopAlbumsOptions.
Returns
Section titled “Returns”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 }
Example
Section titled “Example”const res = await fm.user.getTopAlbums({ user: "USERNAME", limit: 10,});
if (res.success) { console.log(`Top album: ${res.topAlbums[0].name}`);}getTopArtists()
Section titled “getTopArtists()”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.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See UserGetTopArtistsOptions.
Returns
Section titled “Returns”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 }
Example
Section titled “Example”const res = await fm.user.getTopArtists({ user: "USERNAME", limit: 10,});
if (res.success) { console.log(`Top artist: ${res.topArtists[0].name}`);}getTopTracks()
Section titled “getTopTracks()”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.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See UserGetTopTracksOptions.
Returns
Section titled “Returns”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 }
Example
Section titled “Example”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}`);}