From 33d467af1340ea600292812b11e78a847106e75b Mon Sep 17 00:00:00 2001 From: SN0WF14K3 Date: Mon, 28 Jun 2021 12:56:30 +0545 Subject: [PATCH 1/4] Update docs-deploy.yml --- .github/workflows/docs-deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index 827f675..4a3d90c 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -5,6 +5,8 @@ on: - '*' - '!docs' - '!gh-pages' + tags: + - '*' jobs: docs: name: Documentation From 355157a75353ec7e99142fcee86882a86c541a83 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Mon, 28 Jun 2021 23:59:45 +0545 Subject: [PATCH 2/4] revert extractor first --- package.json | 2 +- src/Player.ts | 63 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 541194a..ea00c9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-player", - "version": "4.1.3", + "version": "4.1.4", "description": "Complete framework to facilitate music commands using discord.js", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/Player.ts b/src/Player.ts index b966d53..02c2ddb 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -488,32 +488,53 @@ export class Player extends EventEmitter { if (typeof query === 'string') query = query.replace(/<(.+)>/g, '$1'); let track; - if (query instanceof Track) query = query.url; + if (query instanceof Track) track = query; else { - for (const [_, extractor] of this.Extractors) { - if (extractor.validate(query)) { - const data = await extractor.handle(query); - if (data) { - track = new Track(this, { - title: data.title, - description: data.description, - duration: Util.buildTimeCode(Util.parseMS(data.duration)), - thumbnail: data.thumbnail, - author: data.author, - views: data.views, - engine: data.engine, - source: data.source ?? 'arbitrary', - fromPlaylist: false, - requestedBy: message.author, - url: data.url - }); + if (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]; - if (extractor.important) break; + 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 { + for (const [_, extractor] of this.Extractors) { + if (extractor.validate(query)) { + const data = await extractor.handle(query); + if (data) { + track = new Track(this, { + title: data.title, + description: data.description, + duration: Util.buildTimeCode(Util.parseMS(data.duration)), + thumbnail: data.thumbnail, + author: data.author, + views: data.views, + engine: data.engine, + source: data.source ?? 'arbitrary', + fromPlaylist: false, + requestedBy: message.author, + url: data.url + }); + + if (extractor.important) break; + } } } - } - if (!track) track = await this._searchTracks(message, query, firstResult); + if (!track) track = await this._searchTracks(message, query, firstResult); + } } if (track) { From 563cc2e050ee9dead338ee04c6ff60036d2a3f32 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Tue, 29 Jun 2021 00:03:54 +0545 Subject: [PATCH 3/4] Use youtube-sr getVideo --- src/Player.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Player.ts b/src/Player.ts index 02c2ddb..952b14a 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -491,23 +491,23 @@ export class Player extends EventEmitter { if (query instanceof Track) track = query; else { 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.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]; + 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 = typeof info.thumbnail === "string" ? info.thumbnail : info.thumbnail.url; 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), + title: info.title, + description: info.description || "", + author: info.channel.name, + url: info.url, + thumbnail: lastThumbnail, + duration: Util.buildTimeCode(Util.parseMS(info.duration * 1000)), + views: parseInt(info.views as unknown as string), requestedBy: message.author, fromPlaylist: false, source: 'youtube', - live: Boolean(info.videoDetails.isLiveContent) + live: Boolean(info.live) }); } else { for (const [_, extractor] of this.Extractors) { From 8e876fbfac30bcdfd4f48cb73a2331f1dc381321 Mon Sep 17 00:00:00 2001 From: SN0WF14K3 Date: Tue, 29 Jun 2021 00:08:28 +0545 Subject: [PATCH 4/4] Update Player.ts --- src/Player.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Player.ts b/src/Player.ts index 952b14a..61e3de4 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -1020,6 +1020,7 @@ export class Player extends EventEmitter { }, system: { arch: process.arch, + // @ts-ignore platform: process.platform, cpu: os.cpus().length, memory: {