From 82cfc913c82848ff1c753f4b4c072c43ad31850b Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Thu, 13 May 2021 13:55:41 +0545 Subject: [PATCH] (chore) prettier --- src/Player.ts | 150 +++++++++++++++++++++++++--------------------- src/utils/Util.ts | 10 ++-- 2 files changed, 88 insertions(+), 72 deletions(-) diff --git a/src/Player.ts b/src/Player.ts index 7018fb4..10abc9e 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -207,13 +207,17 @@ export class Player extends EventEmitter { const searchQueryString = this.options.disableArtistSearch ? spotifyTrack.title : `${spotifyTrack.title}${' - ' + spotifyTrack.author}`; - const ytv = await YouTube.search(searchQueryString, { limit: 1, type: "video" }).catch(e => { }); + const ytv = await YouTube.search(searchQueryString, { + limit: 1, + type: 'video' + }).catch((e) => {}); - if (ytv && ytv[0]) Util.define({ - target: spotifyTrack, - prop: 'backupLink', - value: ytv[0].url - }); + if (ytv && ytv[0]) + Util.define({ + target: spotifyTrack, + prop: 'backupLink', + value: ytv[0].url + }); } tracks = [spotifyTrack]; @@ -232,71 +236,83 @@ export class Player extends EventEmitter { let tracks: Track[] = []; if (playlist.type !== 'playlist') - tracks = await Promise.all(playlist.tracks.items.map(async (m: any) => { - const data = new Track(this, { - title: m.name ?? '', - description: m.description ?? '', - author: m.artists[0]?.name ?? 'Unknown Artist', - url: m.external_urls?.spotify ?? query, - thumbnail: - playlist.images[0]?.url ?? m.preview_url?.length - ? `https://i.scdn.co/image/${m.preview_url?.split('?cid=')[1]}` - : 'https://www.scdn.co/i/_global/twitter_card-default.jpg', - duration: Util.buildTimeCode(Util.parseMS(m.duration_ms)), - views: 0, - requestedBy: message.author, - fromPlaylist: true, - source: 'spotify' - }); - - if (this.options.fetchBeforeQueued) { - const searchQueryString = this.options.disableArtistSearch - ? data.title - : `${data.title}${' - ' + data.author}`; - const ytv = await YouTube.search(searchQueryString, { limit: 1, type: "video" }).catch(e => { }); - - if (ytv && ytv[0]) Util.define({ - target: data, - prop: 'backupLink', - value: ytv[0].url + tracks = await Promise.all( + playlist.tracks.items.map(async (m: any) => { + const data = new Track(this, { + title: m.name ?? '', + description: m.description ?? '', + author: m.artists[0]?.name ?? 'Unknown Artist', + url: m.external_urls?.spotify ?? query, + thumbnail: + playlist.images[0]?.url ?? m.preview_url?.length + ? `https://i.scdn.co/image/${m.preview_url?.split('?cid=')[1]}` + : 'https://www.scdn.co/i/_global/twitter_card-default.jpg', + duration: Util.buildTimeCode(Util.parseMS(m.duration_ms)), + views: 0, + requestedBy: message.author, + fromPlaylist: true, + source: 'spotify' }); - } - return data; - })); + if (this.options.fetchBeforeQueued) { + const searchQueryString = this.options.disableArtistSearch + ? data.title + : `${data.title}${' - ' + data.author}`; + const ytv = await YouTube.search(searchQueryString, { + limit: 1, + type: 'video' + }).catch((e) => {}); + + if (ytv && ytv[0]) + Util.define({ + target: data, + prop: 'backupLink', + value: ytv[0].url + }); + } + + return data; + }) + ); else { - tracks = await Promise.all(playlist.tracks.items.map(async (m: any) => { - const data = new Track(this, { - title: m.track.name ?? '', - description: m.track.description ?? '', - author: m.track.artists[0]?.name ?? 'Unknown Artist', - url: m.track.external_urls?.spotify ?? query, - thumbnail: - playlist.images[0]?.url ?? m.track.preview_url?.length - ? `https://i.scdn.co/image/${m.track.preview_url?.split('?cid=')[1]}` - : 'https://www.scdn.co/i/_global/twitter_card-default.jpg', - duration: Util.buildTimeCode(Util.parseMS(m.track.duration_ms)), - views: 0, - requestedBy: message.author, - fromPlaylist: true, - source: 'spotify' - }); - - if (this.options.fetchBeforeQueued) { - const searchQueryString = this.options.disableArtistSearch - ? data.title - : `${data.title}${' - ' + data.author}`; - const ytv = await YouTube.search(searchQueryString, { limit: 1, type: "video" }).catch(e => {}); - - if (ytv && ytv[0]) Util.define({ - target: data, - prop: 'backupLink', - value: ytv[0].url + tracks = await Promise.all( + playlist.tracks.items.map(async (m: any) => { + const data = new Track(this, { + title: m.track.name ?? '', + description: m.track.description ?? '', + author: m.track.artists[0]?.name ?? 'Unknown Artist', + url: m.track.external_urls?.spotify ?? query, + thumbnail: + playlist.images[0]?.url ?? m.track.preview_url?.length + ? `https://i.scdn.co/image/${m.track.preview_url?.split('?cid=')[1]}` + : 'https://www.scdn.co/i/_global/twitter_card-default.jpg', + duration: Util.buildTimeCode(Util.parseMS(m.track.duration_ms)), + views: 0, + requestedBy: message.author, + fromPlaylist: true, + source: 'spotify' }); - } - return data; - })); + if (this.options.fetchBeforeQueued) { + const searchQueryString = this.options.disableArtistSearch + ? data.title + : `${data.title}${' - ' + data.author}`; + const ytv = await YouTube.search(searchQueryString, { + limit: 1, + type: 'video' + }).catch((e) => {}); + + if (ytv && ytv[0]) + Util.define({ + target: data, + prop: 'backupLink', + value: ytv[0].url + }); + } + + return data; + }) + ); } if (!tracks.length) return void this.emit(PlayerEvents.NO_RESULTS, message, query); @@ -1325,7 +1341,7 @@ export class Player extends EventEmitter { const searchQueryString = this.options.disableArtistSearch ? queue.playing.title : `${queue.playing.title}${' - ' + queue.playing.author}`; - const yteqv = await YouTube.search(searchQueryString, { type: "video", limit: 1 }).catch(() => {}); + const yteqv = await YouTube.search(searchQueryString, { type: 'video', limit: 1 }).catch(() => {}); if (!yteqv || !yteqv.length) return void this.emit( diff --git a/src/utils/Util.ts b/src/utils/Util.ts index 68d74f4..12c5671 100644 --- a/src/utils/Util.ts +++ b/src/utils/Util.ts @@ -206,12 +206,12 @@ export class Util { } /** - * - * @param target - * @param prop - * @param value + * + * @param target + * @param prop + * @param value */ - static define(ops: { target: any, prop: any, value: any, enumerate?: boolean }) { + static define(ops: { target: any; prop: any; value: any; enumerate?: boolean }) { Object.defineProperty(ops.target, ops.prop, { value: ops.value, writable: true,