feat(Player): allow searchEngine to accept extractor name

This commit is contained in:
DevAndromeda 2021-11-05 18:38:48 +05:45
parent 6b3874b894
commit 751df78607
2 changed files with 21 additions and 21 deletions

View file

@ -190,7 +190,7 @@ class Player extends EventEmitter<PlayerEvents> {
}
/**
* @typedef {object} SearchResult
* @typedef {object} PlayerSearchResult
* @property {Playlist} [playlist] The playlist (if any)
* @property {Track[]} tracks The tracks
*/
@ -205,7 +205,7 @@ class Player extends EventEmitter<PlayerEvents> {
if (!options) throw new PlayerError("DiscordPlayer#search needs search options!", ErrorStatusCode.INVALID_ARG_TYPE);
options.requestedBy = this.client.users.resolve(options.requestedBy);
if (!("searchEngine" in options)) options.searchEngine = QueryType.AUTO;
if (this.extractors.has(options.searchEngine)) {
if (typeof options.searchEngine === "string" && this.extractors.has(options.searchEngine)) {
const extractor = this.extractors.get(options.searchEngine);
if (!extractor.validate(query)) return { playlist: null, tracks: [] };
const data = await extractor.handle(query);

View file

@ -227,25 +227,25 @@ export interface ExtractorModelData {
* - YOUTUBE_SEARCH
* - YOUTUBE_VIDEO
* - SOUNDCLOUD_SEARCH
* @typedef {string} QueryType
* @typedef {number} QueryType
*/
export enum QueryType {
AUTO = "auto",
YOUTUBE = "youtube",
YOUTUBE_PLAYLIST = "youtube_playlist",
SOUNDCLOUD_TRACK = "soundcloud_track",
SOUNDCLOUD_PLAYLIST = "soundcloud_playlist",
SOUNDCLOUD = "soundcloud",
SPOTIFY_SONG = "spotify_song",
SPOTIFY_ALBUM = "spotify_album",
SPOTIFY_PLAYLIST = "spotify_playlist",
FACEBOOK = "facebook",
VIMEO = "vimeo",
ARBITRARY = "arbitrary",
REVERBNATION = "reverbnation",
YOUTUBE_SEARCH = "youtube_search",
YOUTUBE_VIDEO = "youtube_video",
SOUNDCLOUD_SEARCH = "soundcloud_search"
AUTO,
YOUTUBE,
YOUTUBE_PLAYLIST,
SOUNDCLOUD_TRACK,
SOUNDCLOUD_PLAYLIST,
SOUNDCLOUD,
SPOTIFY_SONG,
SPOTIFY_ALBUM,
SPOTIFY_PLAYLIST,
FACEBOOK,
VIMEO,
ARBITRARY,
REVERBNATION,
YOUTUBE_SEARCH,
YOUTUBE_VIDEO,
SOUNDCLOUD_SEARCH
}
/**
@ -357,12 +357,12 @@ export interface PlayOptions {
/**
* @typedef {object} SearchOptions
* @property {UserResolvable} requestedBy The user who requested this search
* @property {QueryType} [searchEngine=QueryType.AUTO] The query search engine
* @property {QueryType|string} [searchEngine=QueryType.AUTO] The query search engine, can be extractor name to target specific one (custom)
* @property {boolean} [blockExtractor=false] If it should block custom extractors
*/
export interface SearchOptions {
requestedBy: UserResolvable;
searchEngine?: QueryType;
searchEngine?: QueryType | string;
blockExtractor?: boolean;
}