From 082278bfac3078a2948029a0fffeed3af7b556db Mon Sep 17 00:00:00 2001 From: Struck713 Date: Sun, 17 Sep 2023 03:37:25 -0400 Subject: [PATCH] Fixed ytdl bug --- package-lock.json | 47 ++++------------------------------------------- package.json | 3 +-- src/lib/voice.ts | 21 +++++++++++++++------ 3 files changed, 20 insertions(+), 51 deletions(-) diff --git a/package-lock.json b/package-lock.json index 954c4af..d71704a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,8 +15,7 @@ "discord.js": "^14.11.0", "ffmpeg-static": "^5.1.0", "libsodium-wrappers": "^0.7.11", - "yt-dlp-wrap": "^2.3.11", - "ytdl-core": "^4.11.5" + "yt-dlp-wrap": "^2.3.12" }, "devDependencies": { "@types/node": "^20.4.1", @@ -1111,18 +1110,6 @@ "node": ">=10" } }, - "node_modules/m3u8stream": { - "version": "0.8.6", - "resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.8.6.tgz", - "integrity": "sha512-LZj8kIVf9KCphiHmH7sbFQTVe4tOemb202fWwvJwR9W5ENW/1hxJN6ksAWGhQgSBSa3jyWhnjKU1Fw1GaOdbyA==", - "dependencies": { - "miniget": "^4.2.2", - "sax": "^1.2.4" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -1170,14 +1157,6 @@ "node": ">= 0.6" } }, - "node_modules/miniget": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/miniget/-/miniget-4.2.3.tgz", - "integrity": "sha512-SjbDPDICJ1zT+ZvQwK0hUcRY4wxlhhNpHL9nJOB2MEAXRGagTljsO8MEDzQMTFf0Q8g4QNi8P9lEm/g7e+qgzA==", - "engines": { - "node": ">=12" - } - }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -1527,11 +1506,6 @@ } ] }, - "node_modules/sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" - }, "node_modules/semver": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", @@ -1953,22 +1927,9 @@ } }, "node_modules/yt-dlp-wrap": { - "version": "2.3.11", - "resolved": "https://registry.npmjs.org/yt-dlp-wrap/-/yt-dlp-wrap-2.3.11.tgz", - "integrity": "sha512-B0982YLawUC6C8V6hA88bC+EvZ1Mu/dSY+4VcQ8fa60dp1ILT/YWAl4AeowTH+wrrdg6aL7vCXTxlkeacZd5kg==" - }, - "node_modules/ytdl-core": { - "version": "4.11.5", - "resolved": "https://registry.npmjs.org/ytdl-core/-/ytdl-core-4.11.5.tgz", - "integrity": "sha512-27LwsW4n4nyNviRCO1hmr8Wr5J1wLLMawHCQvH8Fk0hiRqrxuIu028WzbJetiYH28K8XDbeinYW4/wcHQD1EXA==", - "dependencies": { - "m3u8stream": "^0.8.6", - "miniget": "^4.2.2", - "sax": "^1.1.3" - }, - "engines": { - "node": ">=12" - } + "version": "2.3.12", + "resolved": "https://registry.npmjs.org/yt-dlp-wrap/-/yt-dlp-wrap-2.3.12.tgz", + "integrity": "sha512-P8fJ+6M1YjukyJENCTviNLiZ8mokxprR54ho3DsSKPWDcac489OjRiStGEARJr6un6ETS6goTn4CWl/b/rM3aA==" } } } diff --git a/package.json b/package.json index 97a23f7..c4d8f63 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,7 @@ "discord.js": "^14.11.0", "ffmpeg-static": "^5.1.0", "libsodium-wrappers": "^0.7.11", - "yt-dlp-wrap": "^2.3.11", - "ytdl-core": "^4.11.5" + "yt-dlp-wrap": "^2.3.12" }, "devDependencies": { "@types/node": "^20.4.1", diff --git a/src/lib/voice.ts b/src/lib/voice.ts index 1934ff5..ed31f2f 100644 --- a/src/lib/voice.ts +++ b/src/lib/voice.ts @@ -1,10 +1,12 @@ +import { YOUTUBE } from "../../config.json"; + import { AudioPlayer, AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResource, getVoiceConnection, joinVoiceChannel } from "@discordjs/voice"; import { VoiceBasedChannel } from "discord.js"; -import ytdl from "ytdl-core"; -import { YoutubeMetadata } from "./utils/youtube"; import { voiceManager } from "../app"; +import { YoutubeMetadata } from "./utils/youtube"; -//const ytdl = new YTDLPWrap('C:/Users/Noah/Programming/JavaScript/BarbarianBot_v2/binaries/yt-dlp.exe'); +import YTDlpWrap from "yt-dlp-wrap"; +const ytdl = new YTDlpWrap(YOUTUBE.BINARY); export class VoiceManager { @@ -89,9 +91,16 @@ export class VoiceConnection { let voiceConnection = this.get(); if (!voiceConnection) return false; - const stream = ytdl(url, { filter: "audioonly" }) - .on("error", _ => this.next()); - this.resource = createAudioResource(stream); + const stream = await ytdl.exec( + [ + "-o", + "-", + url, + "-f", + "bestaudio[ext=m4a],bestaudio[ext=webm]" + ] + ); + this.resource = createAudioResource(stream.ytDlpProcess?.stdout!); this.audioPlayer.play(this.resource); return true;