@solely/simple-fm
Advanced tools
Comparing version 1.1.1 to 1.3.0
@@ -1,2 +0,2 @@ | ||
import type { AlbumGetInfoType, AlbumType } from './types'; | ||
import type { AlbumGetInfoType, AlbumGetTopTagsType, AlbumSearchType } from './types'; | ||
declare class Album { | ||
@@ -9,6 +9,13 @@ private readonly token; | ||
* @param albumName - The name of the album. | ||
* @param userName - The username for the context of the request. If supplied, the user's playcount for this artist's album is included in the response. | ||
* @param userName - The username for the context of the request. | ||
* If supplied, the user's playcount for this artist's album is included in the response. | ||
*/ | ||
fetch(artistName: string, albumName: string, userName?: string): Promise<AlbumGetInfoType>; | ||
/** | ||
* Fetches and returns popular tags for an album. | ||
* @param artistName - The name of the artist. | ||
* @param albumName - The name of the album. | ||
*/ | ||
fetchTopTags(artistName: string, albumName: string): Promise<AlbumGetTopTagsType>; | ||
/** | ||
* Search for an album by name. | ||
@@ -19,4 +26,4 @@ * @param albumName - The name of the album. | ||
* */ | ||
search(albumName: string, limit?: number, page?: number): Promise<AlbumType[]>; | ||
search(albumName: string, limit?: number, page?: number): Promise<AlbumSearchType[]>; | ||
} | ||
export default Album; |
@@ -11,6 +11,7 @@ import { request } from './request.js'; | ||
* @param albumName - The name of the album. | ||
* @param userName - The username for the context of the request. If supplied, the user's playcount for this artist's album is included in the response. | ||
* @param userName - The username for the context of the request. | ||
* If supplied, the user's playcount for this artist's album is included in the response. | ||
*/ | ||
async fetch(artistName, albumName, userName) { | ||
const { album } = await request({ | ||
const { album, album: { tracks: { track }, tags: { tag }, }, } = await request({ | ||
method: 'album.getInfo', | ||
@@ -22,3 +23,3 @@ artist: artistName, | ||
}); | ||
const tags = album.tags.tag.map((tag) => { | ||
const tags = tag.map((tag) => { | ||
return { | ||
@@ -29,7 +30,7 @@ name: tag.name, | ||
}); | ||
const tracks = album.tracks.track.map((track) => { | ||
const tracks = track.map((track) => { | ||
return { | ||
rank: Number(track['@attr'].rank), | ||
name: track.name, | ||
duration: Number(track.duration), | ||
duration: Number(track.duration) || null, | ||
url: track.url, | ||
@@ -40,5 +41,10 @@ }; | ||
name: album.name, | ||
artist: album.artist, | ||
artist: { | ||
name: album.artist, | ||
url: `https://www.last.fm/music/${encodeURIComponent(album.artist)}`, | ||
}, | ||
tags, | ||
tracks, | ||
url: album.url, | ||
image: album.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
@@ -50,2 +56,30 @@ if (userName) | ||
/** | ||
* Fetches and returns popular tags for an album. | ||
* @param artistName - The name of the artist. | ||
* @param albumName - The name of the album. | ||
*/ | ||
async fetchTopTags(artistName, albumName) { | ||
const { toptags: { tag, '@attr': attr }, } = await request({ | ||
method: 'album.getTopTags', | ||
artist: artistName, | ||
album: albumName, | ||
api_key: this.token, | ||
}); | ||
const tags = tag.map((tag) => { | ||
return { | ||
count: tag.count, | ||
name: tag.name, | ||
url: tag.url, | ||
}; | ||
}); | ||
return { | ||
name: attr.album, | ||
artist: { | ||
name: attr.artist, | ||
url: `https://www.last.fm/music/${encodeURIComponent(attr.artist)}`, | ||
}, | ||
tags, | ||
}; | ||
} | ||
/** | ||
* Search for an album by name. | ||
@@ -67,3 +101,6 @@ * @param albumName - The name of the album. | ||
name: album.name, | ||
artist: album.artist, | ||
artist: { | ||
name: album.artist, | ||
url: `https://www.last.fm/music/${encodeURIComponent(album.artist)}`, | ||
}, | ||
url: album.url, | ||
@@ -70,0 +107,0 @@ image: album.image.find((i) => i.size === 'extralarge')?.['#text'] || null, |
@@ -1,2 +0,2 @@ | ||
import type { ArtistType, ArtistAlbumType, ArtistSimilarType, ArtistTagType, ArtistTrackType } from './types'; | ||
import type { ArtistGetInfoType, ArtistSimilarType, ArtistTopAlbumsType, ArtistTopTagsType, ArtistTopTracksType } from './types'; | ||
declare class Artist { | ||
@@ -8,6 +8,13 @@ private readonly token; | ||
* @param artistName - The name of the artist. | ||
* @param username - The username for the context of the request. If supplied, the user's playcount for this artist is included in the response. | ||
* @param userName - The username for the context of the request. | ||
* If supplied, the user's playcount for this artist is included in the response. | ||
* */ | ||
fetch(artistName: string, userName?: string): Promise<ArtistType>; | ||
fetch(artistName: string, userName?: string): Promise<ArtistGetInfoType>; | ||
/** | ||
* Fetches and returns similar artists to this artist. | ||
* @param artistName - The name of the artist. | ||
* @param limit - The number of results to fetch per page. Defaults to 30. | ||
* */ | ||
fetchSimilar(artistName: string, limit?: number): Promise<ArtistSimilarType[]>; | ||
/** | ||
* Fetches and returns popular albums for an artist. | ||
@@ -18,14 +25,8 @@ * @param artistName - The name of the artist. | ||
* */ | ||
fetchAlbums(artistName: string, limit?: number, page?: number): Promise<ArtistAlbumType[]>; | ||
fetchTopAlbums(artistName: string, limit?: number, page?: number): Promise<ArtistTopAlbumsType[]>; | ||
/** | ||
* Fetches and returns similar artists to this artist. | ||
* @param artistName - The name of the artist. | ||
* @param limit - The number of results to fetch per page. Defaults to 30. | ||
* */ | ||
fetchSimilar(artistName: string, limit?: number): Promise<ArtistSimilarType[]>; | ||
/** | ||
* Fetches and returns popular tags for an artist. | ||
* @param artistName - The name of the artist. | ||
* */ | ||
fetchTags(artistName: string): Promise<ArtistTagType[]>; | ||
fetchTopTags(artistName: string): Promise<ArtistTopTagsType[]>; | ||
/** | ||
@@ -37,3 +38,3 @@ * Fetches and returns popular tracks for an artist. | ||
* */ | ||
fetchTracks(artistName: string, limit?: number, page?: number): Promise<ArtistTrackType[]>; | ||
fetchTopTracks(artistName: string, limit?: number, page?: number): Promise<ArtistTopTracksType[]>; | ||
/** | ||
@@ -45,4 +46,4 @@ * Search for an artist by name. | ||
* */ | ||
search(artistName: string, limit?: number, page?: number): Promise<ArtistType[]>; | ||
search(artistName: string, limit?: number, page?: number): Promise<ArtistGetInfoType[]>; | ||
} | ||
export default Artist; |
@@ -10,3 +10,4 @@ import { request } from './request.js'; | ||
* @param artistName - The name of the artist. | ||
* @param username - The username for the context of the request. If supplied, the user's playcount for this artist is included in the response. | ||
* @param userName - The username for the context of the request. | ||
* If supplied, the user's playcount for this artist is included in the response. | ||
* */ | ||
@@ -25,4 +26,3 @@ async fetch(artistName, userName) { | ||
name: artist.name, | ||
url: artist.url, | ||
bio: artist.bio.summary, | ||
description: artist.bio.summary, | ||
stats: { | ||
@@ -32,2 +32,3 @@ scrobbles: Number(artist.stats.playcount), | ||
}, | ||
url: artist.url, | ||
}; | ||
@@ -39,2 +40,23 @@ if (userName) | ||
/** | ||
* Fetches and returns similar artists to this artist. | ||
* @param artistName - The name of the artist. | ||
* @param limit - The number of results to fetch per page. Defaults to 30. | ||
* */ | ||
async fetchSimilar(artistName, limit = 30) { | ||
const { similarartists: { artist }, } = await request({ | ||
method: 'artist.getSimilar', | ||
artist: artistName, | ||
api_key: this.token, | ||
limit, | ||
}); | ||
return artist.map((artist) => { | ||
return { | ||
match: Number(artist.match), | ||
name: artist.name, | ||
url: artist.url, | ||
image: artist.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}); | ||
} | ||
/** | ||
* Fetches and returns popular albums for an artist. | ||
@@ -45,3 +67,3 @@ * @param artistName - The name of the artist. | ||
* */ | ||
async fetchAlbums(artistName, limit = 50, page = 1) { | ||
async fetchTopAlbums(artistName, limit = 50, page = 1) { | ||
const { topalbums: { album }, } = await request({ | ||
@@ -68,27 +90,6 @@ method: 'artist.getTopAlbums', | ||
/** | ||
* Fetches and returns similar artists to this artist. | ||
* @param artistName - The name of the artist. | ||
* @param limit - The number of results to fetch per page. Defaults to 30. | ||
* */ | ||
async fetchSimilar(artistName, limit = 30) { | ||
const { similarartists: { artist }, } = await request({ | ||
method: 'artist.getSimilar', | ||
artist: artistName, | ||
api_key: this.token, | ||
limit, | ||
}); | ||
return artist.map((artist) => { | ||
return { | ||
name: artist.name, | ||
match: Number(artist.match), | ||
url: artist.url, | ||
image: artist.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}); | ||
} | ||
/** | ||
* Fetches and returns popular tags for an artist. | ||
* @param artistName - The name of the artist. | ||
* */ | ||
async fetchTags(artistName) { | ||
async fetchTopTags(artistName) { | ||
const { toptags: { tag }, } = await request({ | ||
@@ -101,5 +102,5 @@ method: 'artist.getTopTags', | ||
return { | ||
timesRanked: tag.count, | ||
name: tag.name, | ||
url: tag.url, | ||
timesRanked: tag.count, | ||
}; | ||
@@ -114,3 +115,3 @@ }); | ||
* */ | ||
async fetchTracks(artistName, limit = 50, page = 1) { | ||
async fetchTopTracks(artistName, limit = 50, page = 1) { | ||
const { toptracks: { track }, } = await request({ | ||
@@ -131,3 +132,2 @@ method: 'artist.getTopTracks', | ||
}, | ||
url: track.url, | ||
stats: { | ||
@@ -137,2 +137,3 @@ scrobbles: Number(track.playcount), | ||
}, | ||
url: track.url, | ||
}; | ||
@@ -158,6 +159,6 @@ }); | ||
name: artist.name, | ||
url: artist.url, | ||
stats: { | ||
listeners: Number(artist.listeners), | ||
}, | ||
url: artist.url, | ||
image: artist.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
@@ -164,0 +165,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import type { ChartArtistType, ChartTagsType, ChartTrackType } from './types'; | ||
import type { ChartTopArtistsType, ChartTopTagsType, ChartTopTracksType } from './types'; | ||
declare class Chart { | ||
@@ -10,3 +10,3 @@ private readonly token; | ||
* */ | ||
fetchTopArtists(limit?: number, page?: number): Promise<ChartArtistType[]>; | ||
fetchTopArtists(limit?: number, page?: number): Promise<ChartTopArtistsType[]>; | ||
/** | ||
@@ -17,3 +17,3 @@ * Fetches and returns the most popular tags for tracks. | ||
* */ | ||
fetchTopTags(limit?: number, page?: number): Promise<ChartTagsType[]>; | ||
fetchTopTags(limit?: number, page?: number): Promise<ChartTopTagsType[]>; | ||
/** | ||
@@ -24,4 +24,4 @@ * Fetches and returns the most popular tracks. | ||
* */ | ||
fetchTopTracks(limit?: number, page?: number): Promise<ChartTrackType[]>; | ||
fetchTopTracks(limit?: number, page?: number): Promise<ChartTopTracksType[]>; | ||
} | ||
export default Chart; |
@@ -23,3 +23,3 @@ import { request } from './request.js'; | ||
stats: { | ||
playCount: Number(artist.playcount), | ||
scrobbles: Number(artist.playcount), | ||
listeners: Number(artist.listeners), | ||
@@ -47,7 +47,7 @@ }, | ||
name: tag.name, | ||
url: tag.url, | ||
stats: { | ||
taggings: Number(tag.taggings), | ||
totalReach: Number(tag.reach), | ||
reach: Number(tag.reach), | ||
}, | ||
url: tag.url, | ||
}; | ||
@@ -72,3 +72,3 @@ }); | ||
stats: { | ||
playCount: Number(track.playcount), | ||
scrobbles: Number(track.playcount), | ||
listeners: Number(track.listeners), | ||
@@ -75,0 +75,0 @@ }, |
import Album from './Album.js'; | ||
import Artist from './Artist.js'; | ||
import Chart from './Chart.js'; | ||
import Country from './Country.js'; | ||
import Geo from './Geo.js'; | ||
import Tag from './Tag.js'; | ||
@@ -14,3 +14,3 @@ import Track from './Track.js'; | ||
readonly chart: Chart; | ||
readonly country: Country; | ||
readonly geo: Geo; | ||
readonly tag: Tag; | ||
@@ -17,0 +17,0 @@ readonly track: Track; |
import Album from './Album.js'; | ||
import Artist from './Artist.js'; | ||
import Chart from './Chart.js'; | ||
import Country from './Country.js'; | ||
import Geo from './Geo.js'; | ||
import Tag from './Tag.js'; | ||
@@ -15,3 +15,3 @@ import Track from './Track.js'; | ||
chart; | ||
country; | ||
geo; | ||
tag; | ||
@@ -27,3 +27,3 @@ track; | ||
this.chart = new Chart(token); | ||
this.country = new Country(token); | ||
this.geo = new Geo(token); | ||
this.tag = new Tag(token); | ||
@@ -30,0 +30,0 @@ this.track = new Track(token); |
@@ -1,2 +0,2 @@ | ||
import type { TagType, TagTrackType } from './types'; | ||
import type { TagGetInfoType, TagTopAlbumsType, TagTopArtistsType, TagTopTagsType, TagTopTracksType, TagWeeklyChartListType } from './types'; | ||
declare class Tag { | ||
@@ -9,9 +9,34 @@ private readonly token; | ||
* */ | ||
fetch(tagName: string): Promise<TagType>; | ||
fetch(tagName: string): Promise<TagGetInfoType>; | ||
/** | ||
* Fetches and returns popular tracks for a tag. | ||
* Fetches and returns popular albums that are tagged by a tag name. | ||
* @param tagName - The name of the tag. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
fetchTracks(tagName: string): Promise<TagTrackType[]>; | ||
fetchTopAlbums(tagName: string, limit?: number, page?: number): Promise<TagTopAlbumsType[]>; | ||
/** | ||
* Fetches and returns popular artists that are tagged by a tag name. | ||
* @param tagName - The name of the tag. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
fetchTopArtists(tagName: string, limit?: number, page?: number): Promise<TagTopArtistsType[]>; | ||
/** | ||
* Fetches and returns popular albums that are tagged by a tag name. | ||
* */ | ||
fetchTopTags(): Promise<TagTopTagsType[]>; | ||
/** | ||
* Fetches and returns popular tracks that are tagged by a tag name. | ||
* @param tagName - The name of the tag. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
fetchTopTracks(tagName: string, limit?: number, page?: number): Promise<TagTopTracksType[]>; | ||
/** | ||
* Fetches and returns a list of available charts for a tag. | ||
* @param tagName - The name of the tag. | ||
* */ | ||
fetchWeeklyChartList(tagName: string): Promise<TagWeeklyChartListType>; | ||
} | ||
export default Tag; |
106
dist/Tag.js
@@ -16,3 +16,2 @@ import { request } from './request.js'; | ||
api_key: this.token, | ||
limit: 1, | ||
}); | ||
@@ -23,12 +22,83 @@ return { | ||
stats: { | ||
userReach: tag.reach, | ||
totalReach: tag.total, | ||
count: tag.total, | ||
reach: tag.reach, | ||
}, | ||
url: `https://www.last.fm/tag/${encodeURIComponent(tag.name)}`, | ||
}; | ||
} | ||
/** | ||
* Fetches and returns popular tracks for a tag. | ||
* Fetches and returns popular albums that are tagged by a tag name. | ||
* @param tagName - The name of the tag. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
async fetchTracks(tagName) { | ||
async fetchTopAlbums(tagName, limit = 50, page = 1) { | ||
const { albums: { album }, } = await request({ | ||
method: 'tag.getTopAlbums', | ||
tag: tagName, | ||
api_key: this.token, | ||
limit, | ||
page, | ||
}); | ||
return album.map((album) => { | ||
return { | ||
rank: Number(album['@attr'].rank), | ||
name: album.name, | ||
artist: { | ||
name: album.artist.name, | ||
url: album.artist.url, | ||
}, | ||
url: album.url, | ||
image: album.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}); | ||
} | ||
/** | ||
* Fetches and returns popular artists that are tagged by a tag name. | ||
* @param tagName - The name of the tag. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
async fetchTopArtists(tagName, limit = 50, page = 1) { | ||
const { topartists: { artist }, } = await request({ | ||
method: 'tag.getTopArtists', | ||
tag: tagName, | ||
api_key: this.token, | ||
limit, | ||
page, | ||
}); | ||
return artist.map((artist) => { | ||
return { | ||
rank: Number(artist['@attr'].rank), | ||
name: artist.name, | ||
url: artist.url, | ||
image: artist.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}); | ||
} | ||
/** | ||
* Fetches and returns popular albums that are tagged by a tag name. | ||
* */ | ||
async fetchTopTags() { | ||
const { toptags: { tag }, } = await request({ | ||
method: 'tag.getTopTags', | ||
api_key: this.token, | ||
}); | ||
return tag.map((tag) => { | ||
return { | ||
name: tag.name, | ||
stats: { | ||
count: tag.count, | ||
reach: tag.reach, | ||
}, | ||
}; | ||
}); | ||
} | ||
/** | ||
* Fetches and returns popular tracks that are tagged by a tag name. | ||
* @param tagName - The name of the tag. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
async fetchTopTracks(tagName, limit = 50, page = 1) { | ||
const { tracks: { track }, } = await request({ | ||
@@ -38,2 +108,4 @@ method: 'tag.getTopTracks', | ||
api_key: this.token, | ||
limit, | ||
page, | ||
}); | ||
@@ -44,3 +116,3 @@ return track.map((track) => { | ||
name: track.name, | ||
duration: Number(track.duration), | ||
duration: Number(track.duration) || null, | ||
artist: { | ||
@@ -55,3 +127,25 @@ name: track.artist.name, | ||
} | ||
/** | ||
* Fetches and returns a list of available charts for a tag. | ||
* @param tagName - The name of the tag. | ||
* */ | ||
async fetchWeeklyChartList(tagName) { | ||
const { weeklychartlist: { chart, '@attr': attr }, } = await request({ | ||
method: 'tag.getWeeklyChartList', | ||
tag: tagName, | ||
api_key: this.token, | ||
}); | ||
const positions = chart.map((chart) => { | ||
return { | ||
from: new Date(Number(chart.from) * 1000), | ||
to: new Date(Number(chart.to) * 1000), | ||
}; | ||
}); | ||
const response = { | ||
name: attr.tag, | ||
positions, | ||
}; | ||
return response; | ||
} | ||
} | ||
export default Tag; |
@@ -1,2 +0,2 @@ | ||
import type { TrackType } from './types'; | ||
import type { TrackGetInfoType, TrackSearchType, TrackSimilarType, TrackTopTagsType } from './types'; | ||
declare class Track { | ||
@@ -6,2 +6,23 @@ private readonly token; | ||
/** | ||
* Fetches and returns metadata information for a track. | ||
* @param artistName - The name of the artist. | ||
* @param trackName - The name of the track. | ||
* @param userName - The username for the context of the request. | ||
* If supplied, the user's playcount for this track and whether they have loved the track is included in the response. | ||
*/ | ||
fetch(artistName: string, trackName: string, userName?: string): Promise<TrackGetInfoType>; | ||
/** | ||
* Fetches and returns similar tracks for this track. | ||
* @param artistName - The name of the artist. | ||
* @param trackName - The name of the track. | ||
* @param limit - The number of results to fetch per page. Defaults to 30. | ||
*/ | ||
fetchSimilar(artistName: string, trackName: string, limit?: number): Promise<TrackSimilarType[]>; | ||
/** | ||
* Fetches and returns popular tags for a track. | ||
* @param artistName - The name of the artist. | ||
* @param trackName - The name of the track. | ||
*/ | ||
fetchTopTags(artistName: string, trackName: string): Promise<TrackTopTagsType>; | ||
/** | ||
* Search for a track by name. | ||
@@ -12,4 +33,4 @@ * @param trackName - The name of the track. | ||
* */ | ||
search(trackName: string, limit?: number, page?: number): Promise<TrackType[]>; | ||
search(trackName: string, limit?: number, page?: number): Promise<TrackSearchType[]>; | ||
} | ||
export default Track; |
@@ -8,2 +8,106 @@ import { request } from './request.js'; | ||
/** | ||
* Fetches and returns metadata information for a track. | ||
* @param artistName - The name of the artist. | ||
* @param trackName - The name of the track. | ||
* @param userName - The username for the context of the request. | ||
* If supplied, the user's playcount for this track and whether they have loved the track is included in the response. | ||
*/ | ||
async fetch(artistName, trackName, userName) { | ||
const { track, track: { album, toptags: { tag }, }, } = await request({ | ||
method: 'track.getInfo', | ||
artist: artistName, | ||
track: trackName, | ||
username: userName, | ||
api_key: this.token, | ||
}); | ||
const tags = tag.map((tag) => { | ||
return { | ||
name: tag.name, | ||
url: tag.url, | ||
}; | ||
}); | ||
const response = { | ||
name: track.name, | ||
duration: Number(track.duration) || null, | ||
stats: { | ||
scrobbles: Number(track.playcount), | ||
listeners: Number(track.listeners), | ||
}, | ||
artist: { | ||
name: track.artist.name, | ||
url: track.artist.url, | ||
}, | ||
album: { | ||
position: Number(album['@attr'].position), | ||
name: album.title, | ||
url: album.url, | ||
}, | ||
tags, | ||
url: track.url, | ||
image: track.album.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
if (userName) { | ||
response.stats.userPlayCount = Number(track.userplaycount); | ||
response.stats.userLoved = Boolean(Number(track.userloved)).valueOf(); | ||
} | ||
return response; | ||
} | ||
/** | ||
* Fetches and returns similar tracks for this track. | ||
* @param artistName - The name of the artist. | ||
* @param trackName - The name of the track. | ||
* @param limit - The number of results to fetch per page. Defaults to 30. | ||
*/ | ||
async fetchSimilar(artistName, trackName, limit = 30) { | ||
const { similartracks: { track }, } = await request({ | ||
method: 'track.getSimilar', | ||
artist: artistName, | ||
track: trackName, | ||
api_key: this.token, | ||
limit, | ||
}); | ||
return track.map((track) => { | ||
return { | ||
name: track.name, | ||
match: Number(track.match), | ||
duration: Number(track.duration) || null, | ||
scrobbles: Number(track.playcount), | ||
artist: { | ||
name: track.artist.name, | ||
url: track.artist.url, | ||
}, | ||
url: track.url, | ||
image: track.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}); | ||
} | ||
/** | ||
* Fetches and returns popular tags for a track. | ||
* @param artistName - The name of the artist. | ||
* @param trackName - The name of the track. | ||
*/ | ||
async fetchTopTags(artistName, trackName) { | ||
const { toptags: { tag, '@attr': attr }, } = await request({ | ||
method: 'track.getTopTags', | ||
artist: artistName, | ||
track: trackName, | ||
api_key: this.token, | ||
}); | ||
const tags = tag.map((tag) => { | ||
return { | ||
count: Number(tag.count), | ||
name: tag.name, | ||
url: tag.url, | ||
}; | ||
}); | ||
return { | ||
name: attr.track, | ||
artist: { | ||
name: attr.artist, | ||
url: `https://www.last.fm/music/${encodeURIComponent(attr.artist)}`, | ||
}, | ||
tags, | ||
}; | ||
} | ||
/** | ||
* Search for a track by name. | ||
@@ -25,5 +129,8 @@ * @param trackName - The name of the track. | ||
name: track.name, | ||
artist: track.artist, | ||
artist: { | ||
name: track.artist, | ||
url: `https://www.last.fm/music/${encodeURIComponent(track.artist)}`, | ||
}, | ||
listeners: Number(track.listeners), | ||
url: track.url, | ||
listeners: Number(track.listeners), | ||
image: track.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
@@ -30,0 +137,0 @@ }; |
@@ -1,10 +0,7 @@ | ||
export declare interface AlbumType { | ||
name: string; | ||
artist: string; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface AlbumGetInfoType { | ||
name: string; | ||
artist: string; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
userPlayCount?: number; | ||
@@ -18,5 +15,28 @@ tags: Array<{ | ||
name: string; | ||
duration: number; | ||
duration: number | null; | ||
url: string; | ||
}>; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface AlbumSearchType { | ||
name: string; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface AlbumGetTopTagsType { | ||
name: string; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
tags: Array<{ | ||
count: number; | ||
name: string; | ||
url: string; | ||
}>; | ||
} |
@@ -1,4 +0,4 @@ | ||
export declare interface ArtistType { | ||
export declare interface ArtistGetInfoType { | ||
name: string; | ||
bio?: string; | ||
description?: string; | ||
stats: { | ||
@@ -11,4 +11,10 @@ scrobbles?: number; | ||
} | ||
export declare interface ArtistAlbumType { | ||
export declare interface ArtistSimilarType { | ||
name: string; | ||
match: number; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface ArtistTopAlbumsType { | ||
name: string; | ||
scrobbles: number; | ||
@@ -22,9 +28,3 @@ artist: { | ||
} | ||
export declare interface ArtistSimilarType { | ||
name: string; | ||
match: number; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface ArtistTrackType { | ||
export declare interface ArtistTopTracksType { | ||
rank: number; | ||
@@ -42,3 +42,3 @@ name: string; | ||
} | ||
export declare interface ArtistTagType { | ||
export declare interface ArtistTopTagsType { | ||
name: string; | ||
@@ -45,0 +45,0 @@ timesRanked: number; |
@@ -1,5 +0,5 @@ | ||
export declare interface ChartArtistType { | ||
export declare interface ChartTopArtistsType { | ||
name: string; | ||
stats: { | ||
playCount: number; | ||
scrobbles: number; | ||
listeners: number; | ||
@@ -10,14 +10,14 @@ }; | ||
} | ||
export declare interface ChartTagsType { | ||
export declare interface ChartTopTagsType { | ||
name: string; | ||
stats: { | ||
taggings: number; | ||
totalReach: number; | ||
reach: number; | ||
}; | ||
url: string; | ||
url?: string; | ||
} | ||
export declare interface ChartTrackType { | ||
export declare interface ChartTopTracksType { | ||
name: string; | ||
stats: { | ||
playCount: number; | ||
scrobbles: number; | ||
listeners: number; | ||
@@ -24,0 +24,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
export type PersonalTagTypes = 'album' | 'artist' | 'track'; | ||
export interface Image { | ||
@@ -5,2 +6,15 @@ '#text': string; | ||
} | ||
export interface Registered { | ||
'#text': number; | ||
unixtime: string; | ||
} | ||
export interface PersonalTagType { | ||
name: string; | ||
artist?: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export interface Album { | ||
@@ -11,9 +25,6 @@ name: string; | ||
image: Image[]; | ||
streamable?: string; | ||
} | ||
export interface Artist { | ||
name: string; | ||
mbid: string; | ||
url: string; | ||
streamable?: string; | ||
image: Image[]; | ||
@@ -24,2 +35,4 @@ } | ||
url?: string; | ||
count?: number; | ||
total?: number; | ||
reach?: number; | ||
@@ -29,4 +42,4 @@ } | ||
name: string; | ||
artist: object | string; | ||
url: string; | ||
streamable: object | string; | ||
image: Image[]; | ||
@@ -38,7 +51,4 @@ } | ||
country: string | null; | ||
registered: Registered; | ||
url: string; | ||
registered: { | ||
unixtime: string; | ||
'#text': number; | ||
}; | ||
image: Image[]; | ||
@@ -49,3 +59,3 @@ } | ||
export * from './ChartType.js'; | ||
export * from './CountryType.js'; | ||
export * from './GeoType.js'; | ||
export * from './TagType.js'; | ||
@@ -52,0 +62,0 @@ export * from './TrackType.js'; |
export * from './AlbumType.js'; | ||
export * from './ArtistType.js'; | ||
export * from './ChartType.js'; | ||
export * from './CountryType.js'; | ||
export * from './GeoType.js'; | ||
export * from './TagType.js'; | ||
@@ -6,0 +6,0 @@ export * from './TrackType.js'; |
@@ -1,9 +0,6 @@ | ||
import type { Album, Tag, Track } from '..'; | ||
import type { Album, Image, Tag, Track } from '..'; | ||
export declare interface AlbumGetInfoResponse { | ||
album: Album & { | ||
tags: { | ||
tag: Array<Tag & { | ||
url: string; | ||
name: string; | ||
}>; | ||
tag: Tag[]; | ||
}; | ||
@@ -26,4 +23,15 @@ artist: string; | ||
}; | ||
url: string; | ||
image: Image[]; | ||
}; | ||
} | ||
export declare interface AlbumGetTopTagsResponse { | ||
toptags: { | ||
tag: Tag[]; | ||
'@attr': { | ||
artist: string; | ||
album: string; | ||
}; | ||
}; | ||
} | ||
export declare interface AlbumSearchResponse { | ||
@@ -30,0 +38,0 @@ results: { |
@@ -27,3 +27,2 @@ import { Album, Artist, Track, Tag } from '..'; | ||
name: string; | ||
mbid: string; | ||
url: string; | ||
@@ -49,3 +48,2 @@ }; | ||
name: string; | ||
mbid: string; | ||
url: string; | ||
@@ -52,0 +50,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import type { Artist, Track, Image, Tag } from '..'; | ||
import type { Artist, Track, Tag } from '..'; | ||
export declare interface ChartGetTopArtistsResponse { | ||
@@ -13,3 +13,2 @@ artists: { | ||
tag: Array<Tag & { | ||
url: string; | ||
taggings: string; | ||
@@ -28,5 +27,4 @@ }>; | ||
}; | ||
image: Image[]; | ||
}>; | ||
}; | ||
} |
export * from './AlbumResponse.js'; | ||
export * from './ArtistResponse.js'; | ||
export * from './ChartResponse.js'; | ||
export * from './CountryResponse.js'; | ||
export * from './GeoResponse.js'; | ||
export * from './TagResponse.js'; | ||
export * from './TrackResponse.js'; | ||
export * from './UserResponse.js'; |
export * from './AlbumResponse.js'; | ||
export * from './ArtistResponse.js'; | ||
export * from './ChartResponse.js'; | ||
export * from './CountryResponse.js'; | ||
export * from './GeoResponse.js'; | ||
export * from './TagResponse.js'; | ||
export * from './TrackResponse.js'; | ||
export * from './UserResponse.js'; |
@@ -1,2 +0,2 @@ | ||
import { Track, Tag } from '..'; | ||
import type { Album, Artist, Track, Tag } from '..'; | ||
export declare interface TagGetInfoResponse { | ||
@@ -11,2 +11,29 @@ tag: Tag & { | ||
} | ||
export declare interface TagGetTopAlbumsResponse { | ||
albums: { | ||
album: Array<Album & { | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
'@attr': { | ||
rank: number; | ||
}; | ||
}>; | ||
}; | ||
} | ||
export declare interface TagGetTopArtistsResponse { | ||
topartists: { | ||
artist: Array<Artist & { | ||
'@attr': { | ||
rank: number; | ||
}; | ||
}>; | ||
}; | ||
} | ||
export declare interface TagGetTopTagsResponse { | ||
toptags: { | ||
tag: Tag[]; | ||
}; | ||
} | ||
export declare interface TagGetTopTracksResponse { | ||
@@ -18,3 +45,2 @@ tracks: { | ||
name: string; | ||
mbid: string; | ||
url: string; | ||
@@ -28,1 +54,12 @@ }; | ||
} | ||
export declare interface TagGetWeeklyChartListResponse { | ||
weeklychartlist: { | ||
chart: Array<{ | ||
from: string; | ||
to: string; | ||
}>; | ||
'@attr': { | ||
tag: string; | ||
}; | ||
}; | ||
} |
@@ -1,2 +0,46 @@ | ||
import { Track } from '..'; | ||
import type { Album, Tag, Track } from '..'; | ||
export declare interface TrackGetInfoResponse { | ||
track: Track & { | ||
duration: string; | ||
listeners: string; | ||
playcount: string; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
toptags: { | ||
tag: Tag[]; | ||
}; | ||
album: Album & { | ||
title: string; | ||
'@attr': { | ||
position: string; | ||
}; | ||
}; | ||
userplaycount?: string; | ||
userloved?: string; | ||
}; | ||
} | ||
export declare interface TrackGetSimilarResponse { | ||
similartracks: { | ||
track: Array<Track & { | ||
playcount: number; | ||
match: number; | ||
duration: number; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
}>; | ||
}; | ||
} | ||
export declare interface TrackGetTopTagsResponse { | ||
toptags: { | ||
tag: Tag[]; | ||
'@attr': { | ||
artist: string; | ||
track: string; | ||
}; | ||
}; | ||
} | ||
export declare interface TrackSearchResponse { | ||
@@ -3,0 +47,0 @@ results: { |
@@ -1,2 +0,9 @@ | ||
import { Artist, Track, User } from '..'; | ||
import type { Album, Artist, Image, Tag, Track, User } from '..'; | ||
export declare interface UserGetArtistsResponse { | ||
artists: { | ||
artist: Array<Artist & { | ||
playcount: string; | ||
}>; | ||
}; | ||
} | ||
export declare interface UserGetInfoResponse { | ||
@@ -10,9 +17,49 @@ user: User; | ||
} | ||
export declare interface UserGetArtistsResponse { | ||
artists: { | ||
artist: Array<Artist & { | ||
playcount: string; | ||
export declare interface UserGetLovedTracksResponse { | ||
lovedtracks: { | ||
track: Array<Track & { | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
date: { | ||
uts: string; | ||
'#text': string; | ||
}; | ||
}>; | ||
}; | ||
} | ||
export declare interface UserGetPersonalTagsResponse { | ||
taggings: { | ||
albums?: { | ||
album: Array<{ | ||
name: string; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image: Image[]; | ||
}>; | ||
}; | ||
artists?: { | ||
artist: Array<{ | ||
name: string; | ||
url: string; | ||
image: Image[]; | ||
}>; | ||
}; | ||
tracks?: { | ||
track: Array<{ | ||
name: string; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image: Image[]; | ||
}>; | ||
}; | ||
}; | ||
} | ||
export declare interface UserGetRecentTracksResponse { | ||
@@ -31,3 +78,40 @@ recenttracks: { | ||
}>; | ||
'@attr': { | ||
user: string; | ||
}; | ||
}; | ||
} | ||
export declare interface UserGetTopAlbumsResponse { | ||
topalbums: { | ||
album: Array<Album & { | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
playcount: string; | ||
'@attr': { | ||
rank: string; | ||
}; | ||
}>; | ||
}; | ||
} | ||
export declare interface UserGetTopTagsResponse { | ||
toptags: { | ||
tag: Tag[]; | ||
}; | ||
} | ||
export declare interface UserGetTopTracksResponse { | ||
toptracks: { | ||
track: Array<Track & { | ||
duration: string; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
'@attr': { | ||
rank: string; | ||
}; | ||
playcount: string; | ||
}>; | ||
}; | ||
} |
@@ -1,13 +0,13 @@ | ||
export declare interface TagType { | ||
export declare interface TagGetInfoType { | ||
name: string; | ||
description: string; | ||
description?: string; | ||
stats: { | ||
userReach?: number; | ||
totalReach?: number; | ||
count?: number; | ||
reach?: number; | ||
}; | ||
url: string; | ||
} | ||
export declare interface TagTrackType { | ||
export declare interface TagTopAlbumsType { | ||
rank: number; | ||
name: string; | ||
duration: number; | ||
artist: { | ||
@@ -20,1 +20,32 @@ name: string; | ||
} | ||
export declare interface TagTopArtistsType { | ||
rank: number; | ||
name: string; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface TagTopTagsType { | ||
name: string; | ||
stats: { | ||
count?: number; | ||
reach?: number; | ||
}; | ||
} | ||
export declare interface TagTopTracksType { | ||
rank: number; | ||
name: string; | ||
duration: number | null; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface TagWeeklyChartListType { | ||
name: string; | ||
positions: Array<{ | ||
from: Date; | ||
to: Date; | ||
}>; | ||
} |
@@ -1,7 +0,56 @@ | ||
export declare interface TrackType { | ||
export declare interface TrackGetInfoType { | ||
name: string; | ||
artist: string; | ||
duration: number | null; | ||
stats: { | ||
scrobbles: number; | ||
listeners: number; | ||
userPlayCount: number | null; | ||
userLoved: boolean; | ||
}; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
album: { | ||
position: number; | ||
name: string; | ||
url: string; | ||
}; | ||
tags?: object[]; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface TrackSearchType { | ||
name: string; | ||
listeners: number; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface TrackSimilarType { | ||
name: string; | ||
match: number; | ||
duration: number | null; | ||
scrobbles: number; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface TrackTopTagsType { | ||
name: string; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
tags: Array<{ | ||
count: number; | ||
name: string; | ||
url: string; | ||
}>; | ||
} |
@@ -1,3 +0,10 @@ | ||
export declare interface UserType { | ||
import type { PersonalTagType } from '.'; | ||
export declare interface UserArtistsType { | ||
name: string; | ||
scrobbles: number; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface UserGetInfoType { | ||
name: string; | ||
realName: string | null; | ||
@@ -9,15 +16,70 @@ country: string | null; | ||
} | ||
export declare interface UserArtistType { | ||
export declare interface UserLovedTracksType { | ||
name: string; | ||
scrobbles: number; | ||
date: Date; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface UserTrackType { | ||
export declare interface UserPersonalTagsType { | ||
album?: Array<PersonalTagType & { | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
}>; | ||
artist?: PersonalTagType[]; | ||
track?: Array<PersonalTagType & { | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
}>; | ||
} | ||
export declare interface UserRecentTrackType { | ||
currentlyPlaying: boolean; | ||
user: string; | ||
url: string; | ||
tracks: Array<{ | ||
name: string; | ||
album: string; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image?: string | null; | ||
}>; | ||
} | ||
export declare interface UserTopAlbumsType { | ||
rank: number; | ||
name: string; | ||
album: string; | ||
artist: string; | ||
playCount: number; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image?: string | null; | ||
} | ||
export declare interface UserTopTagsType { | ||
count: number; | ||
name: string; | ||
url?: string; | ||
} | ||
export declare interface UserTopTracksType { | ||
rank: number; | ||
name: string; | ||
stats: { | ||
duration: number; | ||
userPlayCount: number; | ||
}; | ||
artist: { | ||
name: string; | ||
url: string; | ||
}; | ||
url: string; | ||
image?: string | null; | ||
} |
@@ -1,2 +0,2 @@ | ||
import type { UserType, UserArtistType, UserTrackType } from './types'; | ||
import type { PersonalTagTypes, UserArtistsType, UserGetInfoType, UserLovedTracksType, UserPersonalTagsType, UserRecentTrackType, UserTopAlbumsType, UserTopTagsType, UserTopTracksType } from './types'; | ||
declare class User { | ||
@@ -9,5 +9,5 @@ private readonly token; | ||
* */ | ||
fetch(userName: string): Promise<UserType>; | ||
fetch(userName: string): Promise<UserGetInfoType>; | ||
/** | ||
* Fetches and returns a list of all the artists in a user's library. | ||
* Fetches and returns a list of popular artists in a user's library. | ||
* @param userName - The name of the user. | ||
@@ -17,3 +17,3 @@ * @param limit - The number of results to fetch per page. Defaults to 50. | ||
* */ | ||
fetchArtists(userName: string, limit?: number, page?: number): Promise<UserArtistType[]>; | ||
fetchAllArtists(userName: string, limit?: number, page?: number): Promise<UserArtistsType[]>; | ||
/** | ||
@@ -25,9 +25,45 @@ * Fetches and returns a list of the user's friends. | ||
* */ | ||
fetchFriends(userName: string, limit?: number, page?: number): Promise<UserType[]>; | ||
fetchFriends(userName: string, limit?: number, page?: number): Promise<UserGetInfoType[]>; | ||
/** | ||
* Fetches and returns the most recent track listened by the user. | ||
* Fetches and returns the loved tracks as set by the user. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
fetchRecentTrack(userName: string): Promise<UserTrackType>; | ||
fetchLovedTracks(userName: string, limit?: number, page?: number): Promise<UserLovedTracksType[]>; | ||
/** | ||
* Fetches and returns a list of the user's personal tags. | ||
* @param userName - The name of the user. | ||
* @param tagName - The name of the tag. | ||
* @param tagType - The type of items which have been tagged. | ||
* */ | ||
fetchPersonalTags(userName: string, tagName: string, tagType: PersonalTagTypes): Promise<UserPersonalTagsType>; | ||
/** | ||
* Fetches and returns the most recent tracks listened by the user. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. Maximum is 200. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
fetchRecentTracks(userName: string, limit?: number, page?: number): Promise<UserRecentTrackType>; | ||
/** | ||
* Fetches and returns a list of popular albums in a user's library. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
fetchTopAlbums(userName: string, limit?: number, page?: number): Promise<UserTopAlbumsType[]>; | ||
/** | ||
* Fetches and returns a list of all the tags used by the user. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* */ | ||
fetchTopTags(userName: string, limit?: number): Promise<UserTopTagsType[]>; | ||
/** | ||
* Fetches and returns a list of popular tracks in a user's library. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
fetchTopTracks(userName: string, limit?: number, page?: number): Promise<UserTopTracksType[]>; | ||
} | ||
export default User; |
199
dist/User.js
@@ -16,3 +16,2 @@ import { request } from './request.js'; | ||
api_key: this.token, | ||
limit: 1, | ||
}); | ||
@@ -23,4 +22,4 @@ return { | ||
country: user.country, | ||
registered: new Date(user.registered['#text'] * 1000), | ||
url: user.url, | ||
registered: new Date(user.registered['#text'] * 1000), | ||
image: user.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
@@ -30,3 +29,3 @@ }; | ||
/** | ||
* Fetches and returns a list of all the artists in a user's library. | ||
* Fetches and returns a list of popular artists in a user's library. | ||
* @param userName - The name of the user. | ||
@@ -36,3 +35,3 @@ * @param limit - The number of results to fetch per page. Defaults to 50. | ||
* */ | ||
async fetchArtists(userName, limit = 50, page = 1) { | ||
async fetchAllArtists(userName, limit = 50, page = 1) { | ||
const { artists: { artist }, } = await request({ | ||
@@ -80,22 +79,192 @@ method: 'library.getArtists', | ||
/** | ||
* Fetches and returns the most recent track listened by the user. | ||
* Fetches and returns the loved tracks as set by the user. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
async fetchRecentTrack(userName) { | ||
const { recenttracks } = await request({ | ||
async fetchLovedTracks(userName, limit = 50, page = 1) { | ||
const { lovedtracks: { track }, } = await request({ | ||
method: 'user.getLovedTracks', | ||
user: userName, | ||
api_key: this.token, | ||
limit, | ||
page, | ||
}); | ||
return track.map((track) => { | ||
return { | ||
name: track.name, | ||
date: new Date(Number(track.date.uts) * 1000), | ||
artist: { | ||
name: track.artist.name, | ||
url: track.artist.url, | ||
}, | ||
url: track.url, | ||
}; | ||
}); | ||
} | ||
/** | ||
* Fetches and returns a list of the user's personal tags. | ||
* @param userName - The name of the user. | ||
* @param tagName - The name of the tag. | ||
* @param tagType - The type of items which have been tagged. | ||
* */ | ||
async fetchPersonalTags(userName, tagName, tagType) { | ||
const { taggings } = await request({ | ||
method: 'user.getPersonalTags', | ||
user: userName, | ||
tag: tagName, | ||
taggingtype: tagType, | ||
api_key: this.token, | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
if (!tagType) | ||
throw new Error('No method was selected.'); | ||
const responseTypes = { | ||
album: taggings.albums?.album.map((album) => { | ||
return { | ||
name: album.name, | ||
artist: { | ||
name: album.artist.name, | ||
url: album.artist.url, | ||
}, | ||
url: album.url, | ||
image: album.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}), | ||
artist: taggings.artists?.artist.map((artist) => { | ||
return { | ||
name: artist.name, | ||
url: artist.url, | ||
image: artist.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}), | ||
track: taggings.tracks?.track.map((track) => { | ||
return { | ||
name: track.name, | ||
artist: { | ||
name: track.artist.name, | ||
url: track.artist.url, | ||
}, | ||
url: track.url, | ||
image: track.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}), | ||
}; | ||
const response = responseTypes[tagType]; | ||
return response; | ||
} | ||
/** | ||
* Fetches and returns the most recent tracks listened by the user. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. Maximum is 200. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
async fetchRecentTracks(userName, limit = 50, page = 1) { | ||
const { recenttracks: { track, '@attr': attr }, } = await request({ | ||
method: 'user.getRecentTracks', | ||
user: userName, | ||
api_key: this.token, | ||
limit, | ||
page, | ||
}); | ||
const [track] = recenttracks.track; | ||
return { | ||
currentlyPlaying: track['@attr']?.nowplaying === 'true', | ||
name: track.name, | ||
artist: track.artist['#text'], | ||
album: track.album['#text'], | ||
url: track.url, | ||
image: track.image[3]['#text'], | ||
const tracks = track.map((track) => { | ||
return { | ||
name: track.name, | ||
artist: { | ||
name: track.artist['#text'], | ||
url: `https://www.last.fm/music/${encodeURIComponent(track.artist['#text'])}`, | ||
}, | ||
album: track.album['#text'] || null, | ||
url: track.url, | ||
image: track.image[3]['#text'] || null, | ||
}; | ||
}); | ||
const response = { | ||
currentlyPlaying: track[0]['@attr']?.nowplaying === 'true', | ||
user: attr.user, | ||
url: `https://www.last.fm/user/${encodeURIComponent(attr.user)}`, | ||
tracks, | ||
}; | ||
return response; | ||
} | ||
/** | ||
* Fetches and returns a list of popular albums in a user's library. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
async fetchTopAlbums(userName, limit = 50, page = 1) { | ||
const { topalbums: { album }, } = await request({ | ||
method: 'user.getTopAlbums', | ||
user: userName, | ||
api_key: this.token, | ||
limit, | ||
page, | ||
}); | ||
return album.map((album) => { | ||
return { | ||
rank: Number(album['@attr'].rank), | ||
name: album.name, | ||
playCount: Number(album.playcount), | ||
artist: { | ||
name: album.artist.name, | ||
url: album.artist.url, | ||
}, | ||
url: album.url, | ||
image: album.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}); | ||
} | ||
/** | ||
* Fetches and returns a list of all the tags used by the user. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* */ | ||
async fetchTopTags(userName, limit = 50) { | ||
const { toptags: { tag }, } = await request({ | ||
method: 'user.getTopTags', | ||
user: userName, | ||
api_key: this.token, | ||
limit, | ||
}); | ||
return tag.map((tag) => { | ||
return { | ||
count: Number(tag.count), | ||
name: tag.name, | ||
url: tag.url, | ||
}; | ||
}); | ||
} | ||
/** | ||
* Fetches and returns a list of popular tracks in a user's library. | ||
* @param userName - The name of the user. | ||
* @param limit - The number of results to fetch per page. Defaults to 50. | ||
* @param page - The page number to fetch. Defaults to the first page. | ||
* */ | ||
async fetchTopTracks(userName, limit = 50, page = 1) { | ||
const { toptracks: { track }, } = await request({ | ||
method: 'user.getTopTracks', | ||
user: userName, | ||
api_key: this.token, | ||
limit, | ||
page, | ||
}); | ||
return track.map((track) => { | ||
return { | ||
rank: Number(track['@attr'].rank), | ||
name: track.name, | ||
stats: { | ||
duration: Number(track.duration), | ||
userPlayCount: Number(track.playcount), | ||
}, | ||
artist: { | ||
name: track.artist.name, | ||
url: track.artist.url, | ||
}, | ||
url: track.url, | ||
image: track.image.find((i) => i.size === 'extralarge')?.['#text'] || null, | ||
}; | ||
}); | ||
} | ||
} | ||
export default User; |
{ | ||
"name": "@solely/simple-fm", | ||
"version": "1.1.1", | ||
"version": "1.3.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "license": "Zlib", |
136
README.md
@@ -52,3 +52,3 @@ # simple-fm | ||
_Fetches and returns metadata information for an artist._ | ||
_Fetches and returns metadata information for an album._ | ||
@@ -59,2 +59,9 @@ - #### `artistName`: The name of the artist. | ||
### album.fetchTopTags(artistName, albumName) | ||
_Fetches and returns popular tags for an album._ | ||
- #### `artistName`: The name of the artist. | ||
- #### `albumName`: The name of the album. | ||
### album.search(albumName, limit?, page?) | ||
@@ -65,5 +72,3 @@ | ||
- #### `albumName`: The name of the album. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 30. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
@@ -78,23 +83,20 @@ | ||
- #### `artistName`: The artist's name. | ||
- #### `userName?`: The username for the context of the request. If supplied, the user's playcount for this artist is included in the response. | ||
### artist.fetchAlbums(artistName, limit?, page?) | ||
### artist.fetchSimilar(artistName, limit?) | ||
_Fetches and returns popular albums for an artist._ | ||
_Fetches and returns similar artists to this artist._ | ||
- #### `artistName`: The artist's name. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 30. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
### artist.fetchTopAlbums(artistName, limit?, page?) | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
_Fetches and returns popular albums for an artist._ | ||
### artist.fetchSimilar(artistName, limit?) | ||
_Fetches and returns similar artists to this artist._ | ||
- #### `artistName`: The artist's name. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 30. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
### artist.fetchTags(artistName) | ||
### artist.fetchTopTags(artistName) | ||
@@ -105,3 +107,3 @@ _Fetches and returns popular tags for an artist._ | ||
### artist.fetchTracks(artistName, limit?, page?) | ||
### artist.fetchTopTracks(artistName, limit?, page?) | ||
@@ -111,5 +113,3 @@ _Fetches and returns popular tracks for an artist._ | ||
- #### `artistName`: The artist's name. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
@@ -148,5 +148,5 @@ | ||
## country | ||
## geo | ||
### country.fetchTopArtists(country) | ||
### geo.fetchTopArtists(country, limit?, page?) | ||
@@ -158,4 +158,6 @@ _Fetches and returns the most popular artists by country._ | ||
- #### `country`: The name of the country. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
### country.fetchTopTracks(country) | ||
### geo.fetchTopTracks(country, limit?, page?) | ||
@@ -167,2 +169,4 @@ _Fetches and returns the most popular tracks by country._ | ||
- #### `country`: The name of the country. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
@@ -177,10 +181,56 @@ ## tag | ||
### tag.fetchTracks(tagName) | ||
### tag.fetchTopAlbums(tagName, limit?, page?) | ||
- #### `tagName`: The name of the tag. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
### tag.fetchTopArtists(tagName, limit?, page?) | ||
- #### `tagName`: The name of the tag. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
### tag.fetchTopTags() | ||
_Fetches and returns popular albums that are tagged by a tag name._ | ||
### tag.fetchTopTracks(tagName, limit?, page?) | ||
_Fetches and returns popular tracks for a tag._ | ||
- #### `tagName`: The name of the tag. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
### tag.fetchWeeklyChartList(tagName) | ||
_Fetches and returns a list of available charts for a tag._ | ||
- #### `tagName`: The name of the tag. | ||
## track | ||
### track.fetch(artistName, trackName, userName?) | ||
_Fetches and returns metadata information for a track._ | ||
- #### `artistName`: The name of the artist. | ||
- #### `trackName`: The name of the track. | ||
### track.fetchSimilar(artistName, trackName, limit?) | ||
_Fetches and returns similar tracks for this track._ | ||
- #### `artistName`: The name of the artist. | ||
- #### `trackName`: The name of the track. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 30. | ||
### track.fetchTopTags(artistName, trackName) | ||
_Fetches and returns popular tags for a track._ | ||
- #### `artistName`: The name of the artist. | ||
- #### `trackName`: The name of the track. | ||
### track.search(trackName, limit?, page?) | ||
@@ -191,3 +241,2 @@ | ||
- #### `trackName`: The name of the track. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 30. | ||
@@ -204,3 +253,3 @@ - #### `page?`: The page number to fetch. Defaults to the first page. | ||
### user.fetchArtists(userName, limit?, page?) | ||
### user.fetchAllArtists(userName, limit?, page?) | ||
@@ -210,3 +259,2 @@ _Fetches and returns a list of all the artists in a user's library._ | ||
- #### `userName`: The name of the user. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
@@ -220,12 +268,50 @@ - #### `page?`: The page number to fetch. Defaults to the first page. | ||
- #### `userName`: The name of the user. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
### user.fetchLovedTracks(userName, limit?, page?) | ||
_Fetches and returns the loved tracks as set by the user._ | ||
- #### `userName`: The name of the user. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
### user.fetchRecentTrack(userName) | ||
### user.fetchPersonalTags(userName, tagName, tagType) | ||
_Fetches and returns a list of the user's personal tags._ | ||
- #### `userName`: The name of the user. | ||
- #### `tagName`: The name of the tag. | ||
- ### `tagType`: The type of items which have been tagged. Accepted options: `album`, `artist`, `track` | ||
### user.fetchRecentTracks(userName, limit?, page?) | ||
_Fetches and returns the most recent track listened by the user._ | ||
- #### `userName`: The name of the user. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. Maximum is 200. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
### user.fetchTopAlbums | ||
_Fetches and returns a list of popular albums in a user's library._ | ||
- #### `userName`: The name of the user. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
### user.fetchTopTags(userName, limit?) | ||
- #### `userName`: The name of the user. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
### user.fetchTopTracks(userName, limit?, page?) | ||
_Fetches and returns a list of popular tracks in a user's library._ | ||
- #### `userName`: The name of the user. | ||
- #### `limit?`: The number of results to fetch per page. Defaults to 50. | ||
- #### `page?`: The page number to fetch. Defaults to the first page. | ||
# License | ||
@@ -232,0 +318,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77437
2096
319