From 6e6fbfa5913d72bb68e39a9346c8ceb09f91542a Mon Sep 17 00:00:00 2001 From: Max Isom Date: Mon, 16 Mar 2020 12:10:08 -0500 Subject: [PATCH] Add Spotify artist URL support --- src/commands/play.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commands/play.ts b/src/commands/play.ts index d791be3..b354e5a 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -172,8 +172,13 @@ export default class implements Command { } case 'artist': { - await res.stop('ope, can\'t add a whole artist'); - return; + // Await res.stop('ope, can\'t add a whole artist'); + const uri = parsed as spotifyURI.Artist; + + const {body} = await this.spotify.getArtistTopTracks(uri.id, 'US'); + + tracks.push(...body.tracks); + break; } default: { @@ -185,7 +190,12 @@ export default class implements Command { // Search YouTube for each track const searchForTrack = async (track: SpotifyApi.TrackObjectSimplified): Promise => { try { - const {items: [video]} = await ytsr(`${track.name} ${track.artists[0].name} offical`, {limit: 1}); + const {items} = await ytsr(`${track.name} ${track.artists[0].name} offical`, {limit: 5}); + const video = items.find((item: { type: string }) => item.type === 'video'); + + if (!video) { + throw new Error('No video found for query.'); + } return { title: video.title,