make it suitable for extractor

This commit is contained in:
Snowflake107 2021-06-22 21:55:23 +05:45
parent 1ce6213a04
commit 7f5fc57677

View file

@ -488,7 +488,7 @@ export class Player extends EventEmitter {
if (typeof query === 'string') query = query.replace(/<(.+)>/g, '$1');
let track;
if (query instanceof Track) track = query;
if (query instanceof Track) query = query.url;
else {
for (const [_, extractor] of this.Extractors) {
if (extractor.validate(query)) {
@ -513,28 +513,7 @@ export class Player extends EventEmitter {
}
}
if (!track && ytdl.validateURL(query)) {
const info = await ytdl.getBasicInfo(query).catch(() => {});
if (!info) return void this.emit(PlayerEvents.NO_RESULTS, message, query);
if (info.videoDetails.isLiveContent && !this.options.enableLive) return void this.emit(PlayerEvents.ERROR, PlayerErrorEventCodes.LIVE_VIDEO, message, new PlayerError('Live video is not enabled!'));
const lastThumbnail = info.videoDetails.thumbnails[info.videoDetails.thumbnails.length - 1];
track = new Track(this, {
title: info.videoDetails.title,
description: info.videoDetails.description,
author: info.videoDetails.author.name,
url: info.videoDetails.video_url,
thumbnail: lastThumbnail.url,
duration: Util.buildTimeCode(Util.parseMS(parseInt(info.videoDetails.lengthSeconds) * 1000)),
views: parseInt(info.videoDetails.viewCount),
requestedBy: message.author,
fromPlaylist: false,
source: 'youtube',
live: Boolean(info.videoDetails.isLiveContent)
});
} else {
if (!track) track = await this._searchTracks(message, query, firstResult);
}
if (!track) track = await this._searchTracks(message, query, firstResult);
}
if (track) {