From 10fcfe64f4bf6c17af2f5876787c1e75fed3bd1f Mon Sep 17 00:00:00 2001 From: JonnyBro Date: Tue, 13 Sep 2022 11:59:19 +0500 Subject: [PATCH] lint and fixes --- src/Player.ts | 63 ++++++++++++++++++++++---------------- src/Structures/Queue.ts | 5 ++- src/types/types.ts | 4 +-- src/utils/QueryResolver.ts | 6 ++-- 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/Player.ts b/src/Player.ts index aa93870..bc77831 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -289,13 +289,15 @@ class Player extends EventEmitter { return { playlist: null, tracks: [track] }; } case QueryType.YOUTUBE_SEARCH: { - const videos = await play.search(query, { - limit: 10, - source: { youtube: "video" } - }).catch(Util.noop); + const videos = await play + .search(query, { + limit: 10, + source: { youtube: "video" } + }) + .catch(Util.noop); if (!videos) return { playlist: null, tracks: [] }; - const tracks = videos.map(m => { + const tracks = videos.map((m) => { (m as any).source = "youtube"; // eslint-disable-line @typescript-eslint/no-explicit-any return new Track(this, { title: m.title, @@ -315,10 +317,15 @@ class Player extends EventEmitter { } case QueryType.SOUNDCLOUD_TRACK: case QueryType.SOUNDCLOUD_SEARCH: { - const result = await QueryResolver.resolve(query) === QueryType.SOUNDCLOUD_TRACK ? [{ url: query }] : await play.search(query, { - limit: 5, - source: { soundcloud: "tracks" } - }).catch(() => []); + const result = + (await QueryResolver.resolve(query)) === QueryType.SOUNDCLOUD_TRACK + ? [{ url: query }] + : await play + .search(query, { + limit: 5, + source: { soundcloud: "tracks" } + }) + .catch(() => []); if (!result || !result.length) return { playlist: null, tracks: [] }; const res: Track[] = []; @@ -436,7 +443,7 @@ class Player extends EventEmitter { return { playlist: playlist, tracks: playlist.tracks }; } case QueryType.SOUNDCLOUD_PLAYLIST: { - const data = await play.soundcloud(query).catch(Util.noop) as unknown as SoundCloudPlaylist; + const data = (await play.soundcloud(query).catch(Util.noop)) as unknown as SoundCloudPlaylist; if (!data) return { playlist: null, tracks: [] }; const res = new Playlist(this, { @@ -455,7 +462,7 @@ class Player extends EventEmitter { rawPlaylist: data }); - const songs = await data.all_tracks(); + const songs = await data.all_tracks(); for (const song of songs) { const track = new Track(this, { title: song.name, @@ -476,7 +483,7 @@ class Player extends EventEmitter { return { playlist: res, tracks: res.tracks }; } case QueryType.YOUTUBE_PLAYLIST: { - const ytpl = await play.playlist_info(query, { incomplete: true }).catch(Util.noop) as unknown as YouTubePlayList; + const ytpl = (await play.playlist_info(query, { incomplete: true }).catch(Util.noop)) as unknown as YouTubePlayList; if (!ytpl) return { playlist: null, tracks: [] }; const playlist: Playlist = new Playlist(this, { @@ -495,21 +502,23 @@ class Player extends EventEmitter { rawPlaylist: ytpl }); - const videos = await ytpl.all_videos(); - playlist.tracks = videos.map(video => - new Track(this, { - title: video.title, - description: video.description, - author: video.channel?.name, - url: video.url, - requestedBy: options.requestedBy as User, - thumbnail: Util.last(video.thumbnails).url, - views: video.views, - duration: video.durationRaw, - raw: video, - playlist: playlist, - source: "youtube" - })); + const videos = await ytpl.all_videos(); + playlist.tracks = videos.map( + (video) => + new Track(this, { + title: video.title, + description: video.description, + author: video.channel?.name, + url: video.url, + requestedBy: options.requestedBy as User, + thumbnail: Util.last(video.thumbnails).url, + views: video.views, + duration: video.durationRaw, + raw: video, + playlist: playlist, + source: "youtube" + }) + ); return { playlist: playlist, tracks: playlist.tracks }; } diff --git a/src/Structures/Queue.ts b/src/Structures/Queue.ts index fb2ce00..95fcbee 100644 --- a/src/Structures/Queue.ts +++ b/src/Structures/Queue.ts @@ -691,14 +691,13 @@ class Queue { if (this.options.leaveOnEnd) this.destroy(); return void this.player.emit("queueEnd", this); } - const info = await play.video_info(track.url) - .catch(Util.noop); + const info = await play.video_info(track.url).catch(Util.noop); if (!info) { if (this.options.leaveOnEnd) this.destroy(); return void this.player.emit("queueEnd", this); } - const related = await play.video_info(info.related_videos[1]); + const related = await play.video_info(info.related_videos[1]); const nextTrack = new Track(this.player, { title: related.video_details.title, url: related.video_details.url, diff --git a/src/types/types.ts b/src/types/types.ts index 213ae5a..63f73b1 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -10,7 +10,7 @@ export type FiltersName = keyof QueueFilters; export interface PlayerSearchResult { playlist: Playlist | null; tracks: Track[]; - searched?: boolean; + searched?: boolean; } /** @@ -478,4 +478,4 @@ export interface PlaylistJSON { export interface PlayerInitOptions { autoRegisterExtractor?: boolean; connectionTimeout?: number; -} \ No newline at end of file +} diff --git a/src/utils/QueryResolver.ts b/src/utils/QueryResolver.ts index fc6c2b2..4b673b0 100644 --- a/src/utils/QueryResolver.ts +++ b/src/utils/QueryResolver.ts @@ -25,8 +25,8 @@ class QueryResolver { * @returns {QueryType} */ static async resolve(query: string): Promise { - if (await play.so_validate(query) === "track") return QueryType.SOUNDCLOUD_TRACK; - if (await play.so_validate(query) === "playlist" || query.includes("/sets/")) return QueryType.SOUNDCLOUD_PLAYLIST; + if ((await play.so_validate(query)) === "track") return QueryType.SOUNDCLOUD_TRACK; + if ((await play.so_validate(query)) === "playlist" || query.includes("/sets/")) return QueryType.SOUNDCLOUD_PLAYLIST; if (play.yt_validate(query) === "playlist") return QueryType.YOUTUBE_PLAYLIST; if (play.yt_validate(query) === "video") return QueryType.YOUTUBE_VIDEO; if (spotifySongRegex.test(query)) return QueryType.SPOTIFY_SONG; @@ -46,7 +46,7 @@ class QueryResolver { * @returns {string} */ static async getVimeoID(query: string): Promise { - return await QueryResolver.resolve(query) === QueryType.VIMEO + return (await QueryResolver.resolve(query)) === QueryType.VIMEO ? query .split("/") .filter((x) => !!x)