Use youtube-sr getVideo

This commit is contained in:
Snowflake107 2021-06-29 00:03:54 +05:45
parent 355157a753
commit 563cc2e050

View file

@ -491,23 +491,23 @@ export class Player extends EventEmitter {
if (query instanceof Track) track = query; if (query instanceof Track) track = query;
else { else {
if (ytdl.validateURL(query)) { if (ytdl.validateURL(query)) {
const info = await ytdl.getBasicInfo(query).catch(() => {}); const info = await YouTube.getVideo(query).catch(() => {});
if (!info) return void this.emit(PlayerEvents.NO_RESULTS, message, query); 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!')); if (info.live && !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]; const lastThumbnail = typeof info.thumbnail === "string" ? info.thumbnail : info.thumbnail.url;
track = new Track(this, { track = new Track(this, {
title: info.videoDetails.title, title: info.title,
description: info.videoDetails.description, description: info.description || "",
author: info.videoDetails.author.name, author: info.channel.name,
url: info.videoDetails.video_url, url: info.url,
thumbnail: lastThumbnail.url, thumbnail: lastThumbnail,
duration: Util.buildTimeCode(Util.parseMS(parseInt(info.videoDetails.lengthSeconds) * 1000)), duration: Util.buildTimeCode(Util.parseMS(info.duration * 1000)),
views: parseInt(info.videoDetails.viewCount), views: parseInt(info.views as unknown as string),
requestedBy: message.author, requestedBy: message.author,
fromPlaylist: false, fromPlaylist: false,
source: 'youtube', source: 'youtube',
live: Boolean(info.videoDetails.isLiveContent) live: Boolean(info.live)
}); });
} else { } else {
for (const [_, extractor] of this.Extractors) { for (const [_, extractor] of this.Extractors) {