From 4bb7c0f8a7856067f6c947da9f5b14d4863b9645 Mon Sep 17 00:00:00 2001 From: crackodille Date: Tue, 18 Jun 2024 00:15:21 +0200 Subject: [PATCH] fix(song.ts): changing youtube-sr to ytdl-core in Song.ts makeResource() fix #1644 --- package-lock.json | 16 +++++++++++++++- package.json | 3 ++- structs/Song.ts | 9 ++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index ad1982ee5..071123e9f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,8 @@ "play-dl": "^1.9.7", "soundcloud-downloader": "^0.2.3", "string-progressbar": "^1.0.4", - "youtube-sr": "~4.3.0" + "youtube-sr": "~4.3.0", + "ytdl-core": "^4.11.5" }, "devDependencies": { "@types/i18n": "^0.13.12", @@ -3644,6 +3645,19 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/youtube-sr/-/youtube-sr-4.3.4.tgz", "integrity": "sha512-olSYcR80XigutCrePEXBX3/RJJrWfonJQj7+/ggBiWU0CzTDLE1q8+lpWTWCG0JpzhzILp/IB/Bq/glGqqr1TQ==" + }, + "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" + } } } } diff --git a/package.json b/package.json index 85a2ab207..bb1773174 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "play-dl": "^1.9.7", "soundcloud-downloader": "^0.2.3", "string-progressbar": "^1.0.4", - "youtube-sr": "~4.3.0" + "youtube-sr": "~4.3.0", + "ytdl-core": "^4.11.5" }, "devDependencies": { "@types/i18n": "^0.13.12", diff --git a/structs/Song.ts b/structs/Song.ts index 9e5dd9354..9816485ff 100644 --- a/structs/Song.ts +++ b/structs/Song.ts @@ -4,6 +4,7 @@ import { i18n } from "../utils/i18n"; import { videoPattern, isURL } from "../utils/patterns"; const { stream, video_basic_info } = require("play-dl"); +import ytdl from "ytdl-core"; export interface SongData { url: string; @@ -60,18 +61,20 @@ export class Song { } } - public async makeResource(): Promise | void> { + public async makeResource(): Promise { let playStream; const source = this.url.includes("youtube") ? "youtube" : "soundcloud"; if (source === "youtube") { - playStream = await stream(this.url); + playStream = ytdl(this.url, { filter: "audioonly", liveBuffer: 0, quality: "lowestaudio" }); } if (!stream) return; - return createAudioResource(playStream.stream, { metadata: this, inputType: playStream.type, inlineVolume: true }); + if (!playStream) throw new Error("No stream found"); + + return createAudioResource(playStream, { metadata: this, inlineVolume: true }); } public startMessage() {