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] };
|
return { playlist: null, tracks: [track] };
|
||||||
}
|
}
|
||||||
case QueryType.YOUTUBE_SEARCH: {
|
case QueryType.YOUTUBE_SEARCH: {
|
||||||
const videos = await play.search(query, {
|
const videos = await play
|
||||||
|
.search(query, {
|
||||||
limit: 10,
|
limit: 10,
|
||||||
source: { youtube: "video" }
|
source: { youtube: "video" }
|
||||||
}).catch(Util.noop);
|
})
|
||||||
|
.catch(Util.noop);
|
||||||
if (!videos) return { playlist: null, tracks: [] };
|
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
|
(m as any).source = "youtube"; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||||
return new Track(this, {
|
return new Track(this, {
|
||||||
title: m.title,
|
title: m.title,
|
||||||
|
@ -315,10 +317,15 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
}
|
}
|
||||||
case QueryType.SOUNDCLOUD_TRACK:
|
case QueryType.SOUNDCLOUD_TRACK:
|
||||||
case QueryType.SOUNDCLOUD_SEARCH: {
|
case QueryType.SOUNDCLOUD_SEARCH: {
|
||||||
const result = await QueryResolver.resolve(query) === QueryType.SOUNDCLOUD_TRACK ? [{ url: query }] : await play.search(query, {
|
const result =
|
||||||
|
(await QueryResolver.resolve(query)) === QueryType.SOUNDCLOUD_TRACK
|
||||||
|
? [{ url: query }]
|
||||||
|
: await play
|
||||||
|
.search(query, {
|
||||||
limit: 5,
|
limit: 5,
|
||||||
source: { soundcloud: "tracks" }
|
source: { soundcloud: "tracks" }
|
||||||
}).catch(() => []);
|
})
|
||||||
|
.catch(() => []);
|
||||||
if (!result || !result.length) return { playlist: null, tracks: [] };
|
if (!result || !result.length) return { playlist: null, tracks: [] };
|
||||||
const res: Track[] = [];
|
const res: Track[] = [];
|
||||||
|
|
||||||
|
@ -436,7 +443,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
return { playlist: playlist, tracks: playlist.tracks };
|
return { playlist: playlist, tracks: playlist.tracks };
|
||||||
}
|
}
|
||||||
case QueryType.SOUNDCLOUD_PLAYLIST: {
|
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: [] };
|
if (!data) return { playlist: null, tracks: [] };
|
||||||
|
|
||||||
const res = new Playlist(this, {
|
const res = new Playlist(this, {
|
||||||
|
@ -476,7 +483,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
return { playlist: res, tracks: res.tracks };
|
return { playlist: res, tracks: res.tracks };
|
||||||
}
|
}
|
||||||
case QueryType.YOUTUBE_PLAYLIST: {
|
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: [] };
|
if (!ytpl) return { playlist: null, tracks: [] };
|
||||||
|
|
||||||
const playlist: Playlist = new Playlist(this, {
|
const playlist: Playlist = new Playlist(this, {
|
||||||
|
@ -496,7 +503,8 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
});
|
});
|
||||||
|
|
||||||
const videos = await ytpl.all_videos();
|
const videos = await ytpl.all_videos();
|
||||||
playlist.tracks = videos.map(video =>
|
playlist.tracks = videos.map(
|
||||||
|
(video) =>
|
||||||
new Track(this, {
|
new Track(this, {
|
||||||
title: video.title,
|
title: video.title,
|
||||||
description: video.description,
|
description: video.description,
|
||||||
|
@ -509,7 +517,8 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
raw: video,
|
raw: video,
|
||||||
playlist: playlist,
|
playlist: playlist,
|
||||||
source: "youtube"
|
source: "youtube"
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return { playlist: playlist, tracks: playlist.tracks };
|
return { playlist: playlist, tracks: playlist.tracks };
|
||||||
}
|
}
|
||||||
|
|
|
@ -691,8 +691,7 @@ class Queue<T = unknown> {
|
||||||
if (this.options.leaveOnEnd) this.destroy();
|
if (this.options.leaveOnEnd) this.destroy();
|
||||||
return void this.player.emit("queueEnd", this);
|
return void this.player.emit("queueEnd", this);
|
||||||
}
|
}
|
||||||
const info = await play.video_info(track.url)
|
const info = await play.video_info(track.url).catch(Util.noop);
|
||||||
.catch(Util.noop);
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
if (this.options.leaveOnEnd) this.destroy();
|
if (this.options.leaveOnEnd) this.destroy();
|
||||||
return void this.player.emit("queueEnd", this);
|
return void this.player.emit("queueEnd", this);
|
||||||
|
|
|
@ -25,8 +25,8 @@ class QueryResolver {
|
||||||
* @returns {QueryType}
|
* @returns {QueryType}
|
||||||
*/
|
*/
|
||||||
static async resolve(query: string): Promise<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)) === "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)) === "playlist" || query.includes("/sets/")) return QueryType.SOUNDCLOUD_PLAYLIST;
|
||||||
if (play.yt_validate(query) === "playlist") return QueryType.YOUTUBE_PLAYLIST;
|
if (play.yt_validate(query) === "playlist") return QueryType.YOUTUBE_PLAYLIST;
|
||||||
if (play.yt_validate(query) === "video") return QueryType.YOUTUBE_VIDEO;
|
if (play.yt_validate(query) === "video") return QueryType.YOUTUBE_VIDEO;
|
||||||
if (spotifySongRegex.test(query)) return QueryType.SPOTIFY_SONG;
|
if (spotifySongRegex.test(query)) return QueryType.SPOTIFY_SONG;
|
||||||
|
@ -46,7 +46,7 @@ class QueryResolver {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
static async getVimeoID(query: string): Promise<string> {
|
static async getVimeoID(query: string): Promise<string> {
|
||||||
return await QueryResolver.resolve(query) === QueryType.VIMEO
|
return (await QueryResolver.resolve(query)) === QueryType.VIMEO
|
||||||
? query
|
? query
|
||||||
.split("/")
|
.split("/")
|
||||||
.filter((x) => !!x)
|
.filter((x) => !!x)
|
||||||
|
|
Loading…
Reference in a new issue