From 4e1a156f9be48eaefbd3f6dc09f302db7deaddb2 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Wed, 25 Mar 2020 17:59:09 -0500 Subject: Bump dependencies --- src/services/get-songs.ts | 14 +++++++++++--- src/services/player.ts | 6 ++++-- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/services') diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts index 4e8d955..8cbb60c 100644 --- a/src/services/get-songs.ts +++ b/src/services/get-songs.ts @@ -56,8 +56,16 @@ export default class { const playlist = await this.youtube.playlists.get(listId); const {items} = await this.youtube.playlists.items(listId, {maxResults: '50'}); + interface videoResult { + id: string; + contentDetails: { + videoId: string; + duration: string; + }; + } + // Unfortunately, package doesn't provide a method for this - const res: any = await got('https://www.googleapis.com/youtube/v3/videos', {searchParams: { + const {items: videos}: {items: videoResult[]} = await got('https://www.googleapis.com/youtube/v3/videos', {searchParams: { part: 'contentDetails', id: items.map(item => item.contentDetails.videoId).join(','), key: this.youtubeKey @@ -66,7 +74,7 @@ export default class { const queuedPlaylist = {title: playlist.snippet.title, source: playlist.id}; return items.map(video => { - const length = toSeconds(parse(res.items.find((i: any) => i.id === video.contentDetails.videoId).contentDetails.duration)); + const length = toSeconds(parse(videos.find((i: { id: string }) => i.id === video.contentDetails.videoId)!.contentDetails.duration)); return { title: video.snippet.title, @@ -178,7 +186,7 @@ export default class { private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified, playlist: QueuedPlaylist | null): Promise { try { const {items} = await ytsr(`"${track.name}" "${track.artists[0].name}" offical`, {limit: 5}); - const video = items.find((item: { type: string }) => item.type === 'video'); + const video = items.find(item => item.type === 'video'); if (!video) { throw new Error('No video found for query.'); diff --git a/src/services/player.ts b/src/services/player.ts index ad25744..074fe5d 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -238,7 +238,9 @@ export default class { } shuffle(): void { - this.queue = [...this.queue.slice(0, this.queuePosition + 1), ...shuffle(this.queue.slice(this.queuePosition + 1))]; + const shuffledSongs = shuffle(this.queue.slice(this.queuePosition + 1)); + + this.queue = [...this.queue.slice(0, this.queuePosition + 1), ...shuffledSongs]; } clear(): void { @@ -306,7 +308,7 @@ export default class { const nextBestFormat = (formats: ytdl.videoFormat[]): ytdl.videoFormat | undefined => { if (formats[0].live) { - formats = formats.sort((a, b) => (b as any).audioBitrate - (a as any).audioBitrate); // Bad typings + formats = formats.sort((a, b) => (b as unknown as {audioBitrate: number}).audioBitrate - (a as unknown as {audioBitrate: number}).audioBitrate); // Bad typings return formats.find(format => [128, 127, 120, 96, 95, 94, 93].includes(parseInt(format.itag as unknown as string, 10))); // Bad typings } -- cgit v1.2.3