(chore) prettier

This commit is contained in:
Snowflake107 2021-05-13 13:55:41 +05:45
parent 30af411c07
commit 82cfc913c8
2 changed files with 88 additions and 72 deletions

View file

@ -207,13 +207,17 @@ export class Player extends EventEmitter {
const searchQueryString = this.options.disableArtistSearch const searchQueryString = this.options.disableArtistSearch
? spotifyTrack.title ? spotifyTrack.title
: `${spotifyTrack.title}${' - ' + spotifyTrack.author}`; : `${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({ if (ytv && ytv[0])
target: spotifyTrack, Util.define({
prop: 'backupLink', target: spotifyTrack,
value: ytv[0].url prop: 'backupLink',
}); value: ytv[0].url
});
} }
tracks = [spotifyTrack]; tracks = [spotifyTrack];
@ -232,71 +236,83 @@ export class Player extends EventEmitter {
let tracks: Track[] = []; let tracks: Track[] = [];
if (playlist.type !== 'playlist') if (playlist.type !== 'playlist')
tracks = await Promise.all(playlist.tracks.items.map(async (m: any) => { tracks = await Promise.all(
const data = new Track(this, { playlist.tracks.items.map(async (m: any) => {
title: m.name ?? '', const data = new Track(this, {
description: m.description ?? '', title: m.name ?? '',
author: m.artists[0]?.name ?? 'Unknown Artist', description: m.description ?? '',
url: m.external_urls?.spotify ?? query, author: m.artists[0]?.name ?? 'Unknown Artist',
thumbnail: url: m.external_urls?.spotify ?? query,
playlist.images[0]?.url ?? m.preview_url?.length thumbnail:
? `https://i.scdn.co/image/${m.preview_url?.split('?cid=')[1]}` playlist.images[0]?.url ?? m.preview_url?.length
: 'https://www.scdn.co/i/_global/twitter_card-default.jpg', ? `https://i.scdn.co/image/${m.preview_url?.split('?cid=')[1]}`
duration: Util.buildTimeCode(Util.parseMS(m.duration_ms)), : 'https://www.scdn.co/i/_global/twitter_card-default.jpg',
views: 0, duration: Util.buildTimeCode(Util.parseMS(m.duration_ms)),
requestedBy: message.author, views: 0,
fromPlaylist: true, requestedBy: message.author,
source: 'spotify' 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
}); });
}
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 { else {
tracks = await Promise.all(playlist.tracks.items.map(async (m: any) => { tracks = await Promise.all(
const data = new Track(this, { playlist.tracks.items.map(async (m: any) => {
title: m.track.name ?? '', const data = new Track(this, {
description: m.track.description ?? '', title: m.track.name ?? '',
author: m.track.artists[0]?.name ?? 'Unknown Artist', description: m.track.description ?? '',
url: m.track.external_urls?.spotify ?? query, author: m.track.artists[0]?.name ?? 'Unknown Artist',
thumbnail: url: m.track.external_urls?.spotify ?? query,
playlist.images[0]?.url ?? m.track.preview_url?.length thumbnail:
? `https://i.scdn.co/image/${m.track.preview_url?.split('?cid=')[1]}` playlist.images[0]?.url ?? m.track.preview_url?.length
: 'https://www.scdn.co/i/_global/twitter_card-default.jpg', ? `https://i.scdn.co/image/${m.track.preview_url?.split('?cid=')[1]}`
duration: Util.buildTimeCode(Util.parseMS(m.track.duration_ms)), : 'https://www.scdn.co/i/_global/twitter_card-default.jpg',
views: 0, duration: Util.buildTimeCode(Util.parseMS(m.track.duration_ms)),
requestedBy: message.author, views: 0,
fromPlaylist: true, requestedBy: message.author,
source: 'spotify' 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
}); });
}
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); 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 const searchQueryString = this.options.disableArtistSearch
? queue.playing.title ? queue.playing.title
: `${queue.playing.title}${' - ' + queue.playing.author}`; : `${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) if (!yteqv || !yteqv.length)
return void this.emit( return void this.emit(

View file

@ -206,12 +206,12 @@ export class Util {
} }
/** /**
* *
* @param target * @param target
* @param prop * @param prop
* @param value * @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, { Object.defineProperty(ops.target, ops.prop, {
value: ops.value, value: ops.value,
writable: true, writable: true,