@@ -51,7 +51,7 @@ function formatPlaylistTrack(track: ytpl.Item) {
51
51
return {
52
52
streams : [ { source : 'Youtube' , id : track . id } ] ,
53
53
name : track . title ,
54
- thumbnail : track . thumbnails [ 0 ] . url ,
54
+ thumbnail : getLargestThumbnail ( track . thumbnails ) ,
55
55
artist : track . author . name
56
56
} ;
57
57
}
@@ -93,7 +93,7 @@ async function handleYoutubeVideo(url: string): Promise<YoutubeResult[]> {
93
93
return [ {
94
94
streams : [ { source : 'Youtube' , id : videoDetails . videoId } ] ,
95
95
name : videoDetails . title ,
96
- thumbnail : videoDetails . thumbnails [ 0 ] . url ,
96
+ thumbnail : getLargestThumbnail ( videoDetails . thumbnails ) ,
97
97
artist : { name : videoDetails . ownerChannelName }
98
98
} ] ;
99
99
}
@@ -177,14 +177,14 @@ export const getStreamForId = async (id: string, sourceName: string, useSponsorB
177
177
stream : formatInfo . url ,
178
178
duration : parseInt ( trackInfo . videoDetails . lengthSeconds ) ,
179
179
title : trackInfo . videoDetails . title ,
180
- thumbnail : trackInfo . thumbnail_url ,
180
+ thumbnail : getLargestThumbnail ( trackInfo . videoDetails . thumbnails ) ,
181
181
format : formatInfo . container ,
182
182
skipSegments : segments ,
183
183
originalUrl : videoUrl ,
184
184
isLive : formatInfo . isLive ,
185
185
author : {
186
186
name : trackInfo . videoDetails . author . name ,
187
- thumbnail : trackInfo . videoDetails . author . thumbnails [ 0 ] . url
187
+ thumbnail : getLargestThumbnail ( trackInfo . videoDetails . author . thumbnails )
188
188
}
189
189
} ;
190
190
} catch ( e ) {
@@ -201,11 +201,20 @@ function videoToStreamData(video: SearchVideo, source: string): StreamData {
201
201
stream : undefined ,
202
202
duration : parseInt ( video . duration . text ) ,
203
203
title : video . title ,
204
- thumbnail : video . thumbnails [ 0 ] . url ,
204
+ thumbnail : getLargestThumbnail ( video . thumbnails ) ,
205
205
originalUrl : video . url ,
206
206
author : {
207
207
name : video . channel . name ,
208
- thumbnail : video . thumbnails [ 0 ] . url
208
+ thumbnail : getLargestThumbnail ( video . thumbnails )
209
209
}
210
210
} ;
211
211
}
212
+
213
+ const getLargestThumbnail = ( thumbnails : ytdl . thumbnail [ ] ) : string => {
214
+ const isNotEmpty = thumbnails . length > 0 ;
215
+ const largestThumbnail = isNotEmpty && thumbnails . reduce ( ( prev , current ) => {
216
+ return ( prev . height * prev . width ) > ( current . height * current . width ) ? prev : current ;
217
+ } ) ;
218
+
219
+ return largestThumbnail ?. url ;
220
+ } ;
0 commit comments