Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Spotify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises, unlink } from 'fs-extra'
import SpotifyApi, { IAuth, UserObjectPublic } from './lib/API'
import SpotifyApi, { IAuth, TopTrackDetails, UserObjectPublic } from './lib/API'
import Artist from './lib/details/Atrist'
import Playlist from './lib/details/Playlist'
import SongDetails from './lib/details/Track'
Expand Down Expand Up @@ -68,6 +68,20 @@ export default class SpotifyFetcher extends SpotifyApi {
}
}

/**
* Gets the list of Top Tracks from the given Artists URL
* @param url
* @returns {string[]} having the uri of the tracks
*/
getTopTracksArtist = async (
url: string
) => {
await this.verifyCredentials()
const artistResult = await this.getArtist(url)
const topTracks = (await this.getTopTracksByArtist(artistResult.id))
return topTracks.body.tracks.map((track) => track.album.uri)
}

/**
* Gets the playlist info from URL
* @param url URL of the playlist
Expand Down
9 changes: 9 additions & 0 deletions src/lib/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,22 @@ export default class SpotifyApi {
await this.verifyCredentials()
return (await this.spotifyAPI.getUser(id)) as UserObjectPublic
}
getTopTracksByArtist = async(url:string) =>{
await this.verifyCredentials()
return (await this.spotifyAPI.getArtistTopTracks(url,'IN')) as unknown as TopTrackDetails
}
}

export interface IAuth {
clientId: string
clientSecret: string
}

export interface TopTrackDetails {
body:{
tracks: SpotifyApi.TrackObjectFull[]
}
}
interface ClientCredentialsGrantResponseEX {
access_token: string
expires_in: number
Expand Down