lint and fixes
This commit is contained in:
parent
e036de3ccb
commit
10fcfe64f4
4 changed files with 43 additions and 35 deletions
|
@ -289,13 +289,15 @@ class Player extends EventEmitter<PlayerEvents> {
|
|||
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<PlayerEvents> {
|
|||
}
|
||||
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<PlayerEvents> {
|
|||
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<PlayerEvents> {
|
|||
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<PlayerEvents> {
|
|||
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<PlayerEvents> {
|
|||
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 };
|
||||
}
|
||||
|
|
|
@ -691,14 +691,13 @@ class Queue<T = unknown> {
|
|||
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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ class QueryResolver {
|
|||
* @returns {QueryType}
|
||||
*/
|
||||
static async resolve(query: string): Promise<QueryType> {
|
||||
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<string> {
|
||||
return await QueryResolver.resolve(query) === QueryType.VIMEO
|
||||
return (await QueryResolver.resolve(query)) === QueryType.VIMEO
|
||||
? query
|
||||
.split("/")
|
||||
.filter((x) => !!x)
|
||||
|
|
Loading…
Reference in a new issue