@@ -6,7 +6,7 @@ import { CustomPlugin, DisTubeError, Playlist, Song, checkInvalidKey } from "dis
66import type { VoiceBasedChannel } from "discord.js" ;
77import type { PlayOptions , PlaylistInfo , Queue , SearchResult } from "distube" ;
88
9- const SUPPORTED_TYPES = [ "album" , "artist" , " playlist", "track" ] ;
9+ const SUPPORTED_TYPES = [ "album" , "playlist" , "track" ] ;
1010const API = new SpotifyWebApi ( ) ;
1111const spotify = SpotifyUrlInfo ( fetch ) ;
1212let expirationTime = 0 ;
@@ -22,6 +22,7 @@ declare type SpotifyPluginOptions = {
2222
2323type Falsy = undefined | null | false | 0 | "" ;
2424const isTruthy = < T > ( x : T | Falsy ) : x is T => Boolean ( x ) ;
25+ type ClassMethods < T > = { [ K in keyof T ] : T [ K ] extends ( ...args : any [ ] ) => any ? K : never } [ keyof T ] ;
2526
2627const refreshAPIToken = async ( ) => {
2728 if ( expirationTime <= Date . now ( ) - 60000 ) {
@@ -46,7 +47,7 @@ const getItems = async (data: any): Promise<any[]> => {
4647 } )
4748 ) . body ;
4849 } catch ( e : any ) {
49- process . emitWarning ( `${ e ?. body ?. message } ` , "SpotifyAPI " ) ;
50+ process . emitWarning ( `${ e ?. body ?. message } ` , "SpotifyApi " ) ;
5051 process . emitWarning ( "There is a Spotify API error, max songs of Spotify playlist is 100." , "SpotifyPlugin" ) ;
5152 break ;
5253 }
@@ -55,7 +56,8 @@ const getItems = async (data: any): Promise<any[]> => {
5556 return items ;
5657} ;
5758
58- const getAPI = ( method : string , ...args : any ) => ( < any > API ) [ method ] ( ...args ) . then ( ( r : any ) => r . body ) ;
59+ const getAPI = < T extends ClassMethods < typeof API > > ( method : T , ...args : Parameters < typeof API [ T ] > ) =>
60+ ( < any > API [ method ] ) ( ...args ) . then ( ( r : any ) => r . body ) ;
5961
6062const getDataWithAPI = async ( url : string ) => {
6163 const parsedURL = parseSpotifyURI ( url ) ;
@@ -72,10 +74,6 @@ const getDataWithAPI = async (url: string) => {
7274 data = await getAPI ( "getAlbum" , id ) ;
7375 data . tracks = await getAPI ( "getAlbumTracks" , id , { limit : 50 } ) ;
7476 break ;
75- case "artist" :
76- data = await getAPI ( "getArtist" , id ) ;
77- data . tracks = ( await getAPI ( "getArtistTopTracks" , id , "US" ) ) . tracks ;
78- break ;
7977 case "playlist" :
8078 data = await getAPI ( "getPlaylist" , id ) ;
8179 data . tracks = await getAPI ( "getPlaylistTracks" , id , { limit : 100 } ) ;
@@ -100,21 +98,31 @@ export class SpotifyPlugin extends CustomPlugin {
10098 checkInvalidKey ( options , [ "parallel" , "emitEventsAfterFetching" , "api" ] , "SpotifyPluginOptions" ) ;
10199 this . parallel = options . parallel ?? true ;
102100 if ( typeof this . parallel !== "boolean" ) {
103- throw new DisTubeError ( "INVALID_TYPE" , "boolean" , this . parallel , "parallel" ) ;
101+ throw new DisTubeError ( "INVALID_TYPE" , "boolean" , this . parallel , "SpotifyPluginOptions. parallel" ) ;
104102 }
105103 this . emitEventsAfterFetching = options . emitEventsAfterFetching ?? false ;
106104 if ( typeof this . emitEventsAfterFetching !== "boolean" ) {
107- throw new DisTubeError ( "INVALID_TYPE" , "boolean" , this . emitEventsAfterFetching , "emitEventsAfterFetching" ) ;
105+ throw new DisTubeError (
106+ "INVALID_TYPE" ,
107+ "boolean" ,
108+ this . emitEventsAfterFetching ,
109+ "SpotifyPluginOptions.emitEventsAfterFetching" ,
110+ ) ;
108111 }
109112 API . setAccessToken ( "" ) ;
110113 if ( options . api !== undefined && ( typeof options . api !== "object" || Array . isArray ( options . api ) ) ) {
111114 throw new DisTubeError ( "INVALID_TYPE" , [ "object" , "undefined" ] , options . api , "api" ) ;
112115 } else if ( options . api ) {
113116 if ( typeof options . api . clientId !== "string" ) {
114- throw new DisTubeError ( "INVALID_TYPE" , "string" , options . api . clientId , "api.clientId" ) ;
117+ throw new DisTubeError ( "INVALID_TYPE" , "string" , options . api . clientId , "SpotifyPluginOptions. api.clientId" ) ;
115118 }
116119 if ( typeof options . api . clientSecret !== "string" ) {
117- throw new DisTubeError ( "INVALID_TYPE" , "string" , options . api . clientSecret , "api.clientSecret" ) ;
120+ throw new DisTubeError (
121+ "INVALID_TYPE" ,
122+ "string" ,
123+ options . api . clientSecret ,
124+ "SpotifyPluginOptions.api.clientSecret" ,
125+ ) ;
118126 }
119127 API . setClientId ( options . api . clientId ) ;
120128 API . setClientSecret ( options . api . clientSecret ) ;
@@ -163,7 +171,7 @@ export class SpotifyPlugin extends CustomPlugin {
163171 await DT . play ( voiceChannel , result , options ) ;
164172 } else {
165173 const name = data . name ;
166- const thumbnail = data . images [ 0 ] ?. url ;
174+ const thumbnail = ( data . coverArt ?. sources || data . images ) ?. [ 0 ] ?. url ;
167175 const queries : string [ ] = ( await getItems ( data ) )
168176 . map ( item => {
169177 const track = item . track || item ;
0 commit comments