From c446e0fd57cec0ea2fb0211bd99841e5ddde0cf6 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 13 Mar 2020 12:17:45 -0500 Subject: [PATCH] Add artist field --- src/commands/play.ts | 28 +++++++++++++++++++++++----- src/services/queue.ts | 1 + 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/commands/play.ts b/src/commands/play.ts index 5a96bb6..d0d77d1 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -42,7 +42,13 @@ export default class implements Command { const addSingleSong = async (source: string): Promise => { const videoDetails = await this.youtube.videos.get(source); - newSongs.push({title: videoDetails.snippet.title, length: toSeconds(parse(videoDetails.contentDetails.duration)), url: videoDetails.id, playlist: null}); + newSongs.push({ + title: videoDetails.snippet.title, + artist: videoDetails.snippet.channelTitle, + length: toSeconds(parse(videoDetails.contentDetails.duration)), + url: videoDetails.id, + playlist: null + }); }; // Test if it's a complete URL @@ -70,7 +76,13 @@ export default class implements Command { items.forEach(video => { const length = toSeconds(parse(res.items.find((i: any) => i.id === video.contentDetails.videoId).contentDetails.duration)); - newSongs.push({title: video.snippet.title, length, url: video.contentDetails.videoId, playlist: queuedPlaylist}); + newSongs.push({ + title: video.snippet.title, + artist: video.snippet.channelTitle, + length, + url: video.contentDetails.videoId, + playlist: queuedPlaylist + }); }); } else { // Single video @@ -144,11 +156,17 @@ export default class implements Command { } // Search YouTube for each track - const searchForTrack = async (track: any): Promise => { + const searchForTrack = async (track: SpotifyApi.TrackObjectSimplified): Promise => { try { - const {items: [video]} = await ytsr(`${track.name as string} ${track.artists[0].name as string} offical`, {limit: 1}); + const {items: [video]} = await ytsr(`${track.name} ${track.artists[0].name} offical`, {limit: 1}); - return {title: video.title, length: track.duration_ms / 1000, url: video.link, playlist}; + return { + title: video.title, + artist: track.artists[0].name, + length: track.duration_ms / 1000, + url: video.link, + playlist + }; } catch (_) { // TODO: handle error return null; diff --git a/src/services/queue.ts b/src/services/queue.ts index 0e0fd07..85777e5 100644 --- a/src/services/queue.ts +++ b/src/services/queue.ts @@ -7,6 +7,7 @@ export interface QueuedPlaylist { export interface QueuedSong { title: string; + artist: string; url: string; length: number; playlist: QueuedPlaylist | null;