feat(Player): allow searchEngine to accept extractor name
This commit is contained in:
parent
6b3874b894
commit
751df78607
2 changed files with 21 additions and 21 deletions
|
@ -190,7 +190,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {object} SearchResult
|
* @typedef {object} PlayerSearchResult
|
||||||
* @property {Playlist} [playlist] The playlist (if any)
|
* @property {Playlist} [playlist] The playlist (if any)
|
||||||
* @property {Track[]} tracks The tracks
|
* @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);
|
if (!options) throw new PlayerError("DiscordPlayer#search needs search options!", ErrorStatusCode.INVALID_ARG_TYPE);
|
||||||
options.requestedBy = this.client.users.resolve(options.requestedBy);
|
options.requestedBy = this.client.users.resolve(options.requestedBy);
|
||||||
if (!("searchEngine" in options)) options.searchEngine = QueryType.AUTO;
|
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);
|
const extractor = this.extractors.get(options.searchEngine);
|
||||||
if (!extractor.validate(query)) return { playlist: null, tracks: [] };
|
if (!extractor.validate(query)) return { playlist: null, tracks: [] };
|
||||||
const data = await extractor.handle(query);
|
const data = await extractor.handle(query);
|
||||||
|
|
|
@ -227,25 +227,25 @@ export interface ExtractorModelData {
|
||||||
* - YOUTUBE_SEARCH
|
* - YOUTUBE_SEARCH
|
||||||
* - YOUTUBE_VIDEO
|
* - YOUTUBE_VIDEO
|
||||||
* - SOUNDCLOUD_SEARCH
|
* - SOUNDCLOUD_SEARCH
|
||||||
* @typedef {string} QueryType
|
* @typedef {number} QueryType
|
||||||
*/
|
*/
|
||||||
export enum QueryType {
|
export enum QueryType {
|
||||||
AUTO = "auto",
|
AUTO,
|
||||||
YOUTUBE = "youtube",
|
YOUTUBE,
|
||||||
YOUTUBE_PLAYLIST = "youtube_playlist",
|
YOUTUBE_PLAYLIST,
|
||||||
SOUNDCLOUD_TRACK = "soundcloud_track",
|
SOUNDCLOUD_TRACK,
|
||||||
SOUNDCLOUD_PLAYLIST = "soundcloud_playlist",
|
SOUNDCLOUD_PLAYLIST,
|
||||||
SOUNDCLOUD = "soundcloud",
|
SOUNDCLOUD,
|
||||||
SPOTIFY_SONG = "spotify_song",
|
SPOTIFY_SONG,
|
||||||
SPOTIFY_ALBUM = "spotify_album",
|
SPOTIFY_ALBUM,
|
||||||
SPOTIFY_PLAYLIST = "spotify_playlist",
|
SPOTIFY_PLAYLIST,
|
||||||
FACEBOOK = "facebook",
|
FACEBOOK,
|
||||||
VIMEO = "vimeo",
|
VIMEO,
|
||||||
ARBITRARY = "arbitrary",
|
ARBITRARY,
|
||||||
REVERBNATION = "reverbnation",
|
REVERBNATION,
|
||||||
YOUTUBE_SEARCH = "youtube_search",
|
YOUTUBE_SEARCH,
|
||||||
YOUTUBE_VIDEO = "youtube_video",
|
YOUTUBE_VIDEO,
|
||||||
SOUNDCLOUD_SEARCH = "soundcloud_search"
|
SOUNDCLOUD_SEARCH
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -357,12 +357,12 @@ export interface PlayOptions {
|
||||||
/**
|
/**
|
||||||
* @typedef {object} SearchOptions
|
* @typedef {object} SearchOptions
|
||||||
* @property {UserResolvable} requestedBy The user who requested this search
|
* @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
|
* @property {boolean} [blockExtractor=false] If it should block custom extractors
|
||||||
*/
|
*/
|
||||||
export interface SearchOptions {
|
export interface SearchOptions {
|
||||||
requestedBy: UserResolvable;
|
requestedBy: UserResolvable;
|
||||||
searchEngine?: QueryType;
|
searchEngine?: QueryType | string;
|
||||||
blockExtractor?: boolean;
|
blockExtractor?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue