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
|
||||||
limit: 10,
|
.search(query, {
|
||||||
source: { youtube: "video" }
|
limit: 10,
|
||||||
}).catch(Util.noop);
|
source: { youtube: "video" }
|
||||||
|
})
|
||||||
|
.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 =
|
||||||
limit: 5,
|
(await QueryResolver.resolve(query)) === QueryType.SOUNDCLOUD_TRACK
|
||||||
source: { soundcloud: "tracks" }
|
? [{ url: query }]
|
||||||
}).catch(() => []);
|
: await play
|
||||||
|
.search(query, {
|
||||||
|
limit: 5,
|
||||||
|
source: { soundcloud: "tracks" }
|
||||||
|
})
|
||||||
|
.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, {
|
||||||
|
@ -455,7 +462,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
rawPlaylist: data
|
rawPlaylist: data
|
||||||
});
|
});
|
||||||
|
|
||||||
const songs = await data.all_tracks();
|
const songs = await data.all_tracks();
|
||||||
for (const song of songs) {
|
for (const song of songs) {
|
||||||
const track = new Track(this, {
|
const track = new Track(this, {
|
||||||
title: song.name,
|
title: song.name,
|
||||||
|
@ -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, {
|
||||||
|
@ -495,21 +502,23 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
rawPlaylist: ytpl
|
rawPlaylist: ytpl
|
||||||
});
|
});
|
||||||
|
|
||||||
const videos = await ytpl.all_videos();
|
const videos = await ytpl.all_videos();
|
||||||
playlist.tracks = videos.map(video =>
|
playlist.tracks = videos.map(
|
||||||
new Track(this, {
|
(video) =>
|
||||||
title: video.title,
|
new Track(this, {
|
||||||
description: video.description,
|
title: video.title,
|
||||||
author: video.channel?.name,
|
description: video.description,
|
||||||
url: video.url,
|
author: video.channel?.name,
|
||||||
requestedBy: options.requestedBy as User,
|
url: video.url,
|
||||||
thumbnail: Util.last(video.thumbnails).url,
|
requestedBy: options.requestedBy as User,
|
||||||
views: video.views,
|
thumbnail: Util.last(video.thumbnails).url,
|
||||||
duration: video.durationRaw,
|
views: video.views,
|
||||||
raw: video,
|
duration: video.durationRaw,
|
||||||
playlist: playlist,
|
raw: video,
|
||||||
source: "youtube"
|
playlist: playlist,
|
||||||
}));
|
source: "youtube"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return { playlist: playlist, tracks: playlist.tracks };
|
return { playlist: playlist, tracks: playlist.tracks };
|
||||||
}
|
}
|
||||||
|
|
|
@ -691,14 +691,13 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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, {
|
const nextTrack = new Track(this.player, {
|
||||||
title: related.video_details.title,
|
title: related.video_details.title,
|
||||||
url: related.video_details.url,
|
url: related.video_details.url,
|
||||||
|
|
|
@ -10,7 +10,7 @@ export type FiltersName = keyof QueueFilters;
|
||||||
export interface PlayerSearchResult {
|
export interface PlayerSearchResult {
|
||||||
playlist: Playlist | null;
|
playlist: Playlist | null;
|
||||||
tracks: Track[];
|
tracks: Track[];
|
||||||
searched?: boolean;
|
searched?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -478,4 +478,4 @@ export interface PlaylistJSON {
|
||||||
export interface PlayerInitOptions {
|
export interface PlayerInitOptions {
|
||||||
autoRegisterExtractor?: boolean;
|
autoRegisterExtractor?: boolean;
|
||||||
connectionTimeout?: number;
|
connectionTimeout?: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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