diff --git a/README.md b/README.md index 9d80f16ec..c4d047d68 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,8 @@ $ yarn add ytdl-core $ yarn add play-dl # or $ yarn add @distube/ytdl-core +# or +$ yarn add yt-stream ``` Done with all these? Let's write a simple music bot then. diff --git a/examples/karasu/yarn.lock b/examples/karasu/yarn.lock index 8b1c82635..283ee4f03 100644 --- a/examples/karasu/yarn.lock +++ b/examples/karasu/yarn.lock @@ -160,19 +160,6 @@ __metadata: languageName: node linkType: hard -"@discordjs/voice@npm:latest": - version: 0.14.0 - resolution: "@discordjs/voice@npm:0.14.0" - dependencies: - "@types/ws": ^8.5.3 - discord-api-types: ^0.37.20 - prism-media: ^1.3.4 - tslib: ^2.4.1 - ws: ^8.11.0 - checksum: baa68a324f8c7b4a7863a966e7d10a01a4df93aa68800f867e7a6fef016fcd16306ff5a562674884192b0e6538e53e8404d114a7c9781f0637c8e0dea3bca368 - languageName: node - linkType: hard - "@esbuild/android-arm64@npm:0.17.8": version: 0.17.8 resolution: "@esbuild/android-arm64@npm:0.17.8" @@ -806,7 +793,7 @@ __metadata: languageName: node linkType: hard -"@types/ws@npm:^8.5.3, @types/ws@npm:^8.5.4": +"@types/ws@npm:^8.5.4": version: 8.5.4 resolution: "@types/ws@npm:8.5.4" dependencies: @@ -1372,13 +1359,6 @@ __metadata: languageName: node linkType: hard -"discord-api-types@npm:^0.37.20": - version: 0.37.33 - resolution: "discord-api-types@npm:0.37.33" - checksum: d1e31106081ef79d3ea721b8991c5de155879e6d01c47a025b2c41e0496b551608e72e383caf23680938219099b6c3bd43cbacf48edeb7fc9a3c1730c1811ba8 - languageName: node - linkType: hard - "discord-api-types@npm:^0.37.35, discord-api-types@npm:^0.37.36": version: 0.37.36 resolution: "discord-api-types@npm:0.37.36" @@ -1397,12 +1377,12 @@ __metadata: version: 0.0.0-use.local resolution: "discord-player@portal:../../packages/discord-player::locator=karasu-music-bot%40workspace%3A." dependencies: - "@discord-player/equalizer": "*" - "@discord-player/utils": "*" - "@discordjs/voice": latest + "@discord-player/equalizer": "workspace:^" + "@discord-player/utils": "workspace:^" + "@discordjs/voice": 0.16.0 libsodium-wrappers: ^0.7.10 peerDependencies: - "@discord-player/extractor": "*" + "@discord-player/extractor": "workspace:^" discord.js: 14.x youtube-sr: 4.x languageName: node @@ -3467,27 +3447,6 @@ __metadata: languageName: node linkType: hard -"prism-media@npm:^1.3.4": - version: 1.3.4 - resolution: "prism-media@npm:1.3.4" - peerDependencies: - "@discordjs/opus": ^0.8.0 - ffmpeg-static: ^5.0.2 || ^4.2.7 || ^3.0.0 || ^2.4.0 - node-opus: ^0.3.3 - opusscript: ^0.0.8 - peerDependenciesMeta: - "@discordjs/opus": - optional: true - ffmpeg-static: - optional: true - node-opus: - optional: true - opusscript: - optional: true - checksum: 703be28c87b4694714a52a0ea84516b19d2e62e510d0f204efc074b044ad93dde00241d4b4741c25aa2e27a00e3b472e60ad0f6c94e88710f0827dc63889373a - languageName: node - linkType: hard - "prism-media@npm:^1.3.5": version: 1.3.5 resolution: "prism-media@npm:1.3.5" @@ -4327,7 +4286,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:2.x, tslib@npm:^2.3.1, tslib@npm:^2.4.0, tslib@npm:^2.4.1, tslib@npm:^2.5.0": +"tslib@npm:2.x, tslib@npm:^2.3.1, tslib@npm:^2.4.0, tslib@npm:^2.5.0": version: 2.5.0 resolution: "tslib@npm:2.5.0" checksum: ae3ed5f9ce29932d049908ebfdf21b3a003a85653a9a140d614da6b767a93ef94f460e52c3d787f0e4f383546981713f165037dc2274df212ea9f8a4541004e1 @@ -4575,21 +4534,6 @@ __metadata: languageName: node linkType: hard -"ws@npm:^8.11.0": - version: 8.12.0 - resolution: "ws@npm:8.12.0" - peerDependencies: - bufferutil: ^4.0.1 - utf-8-validate: ">=5.0.2" - peerDependenciesMeta: - bufferutil: - optional: true - utf-8-validate: - optional: true - checksum: 818ff3f8749c172a95a114cceb8b89cedd27e43a82d65c7ad0f7882b1e96a2ee6709e3746a903c3fa88beec0c8bae9a9fcd75f20858b32a166dfb7519316a5d7 - languageName: node - linkType: hard - "ws@npm:^8.13.0": version: 8.13.0 resolution: "ws@npm:8.13.0" diff --git a/packages/extractor/package.json b/packages/extractor/package.json index 50b011c40..40cf76f29 100644 --- a/packages/extractor/package.json +++ b/packages/extractor/package.json @@ -39,6 +39,7 @@ "@types/node-fetch": "^2.6.2", "discord-player": "workspace:^", "play-dl": "^1.9.6", + "yt-stream": "^1.4.5", "ytdl-core": "^4.11.2" }, "dependencies": { diff --git a/packages/extractor/src/extractors/common/helper.ts b/packages/extractor/src/extractors/common/helper.ts index c3b4fc81b..3a3e39743 100644 --- a/packages/extractor/src/extractors/common/helper.ts +++ b/packages/extractor/src/extractors/common/helper.ts @@ -12,7 +12,8 @@ export const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 export const YouTubeLibs = [ 'ytdl-core', '@distube/ytdl-core', - 'play-dl' + 'play-dl', + "yt-stream" // add more to the list if you have any ]; @@ -76,7 +77,7 @@ export async function loadYtdl(options?: any, force = false) { const fmt = formats.find((format) => !format.hasVideo) || formats.sort((a, b) => Number(a.bitrate) - Number(b.bitrate))[0]; return fmt.url; // return dl(query, this.context.player.options.ytdlOptions); - } else { + } else if (_ytLibName === "play-dl") { const dl = lib as typeof import('play-dl'); const info = await dl.video_info(query); @@ -92,6 +93,23 @@ export async function loadYtdl(options?: any, force = false) { const fmt = formats.find((format) => !format.qualityLabel) || formats.sort((a, b) => Number(a.bitrate) - Number(b.bitrate))[0]; return fmt.url!; // return (await dl.stream(query, { discordPlayerCompatibility: true })).stream; + } else { + const dl = lib as typeof import("yt-stream") + + // @ts-ignore Default lib did not provide types for this function + const decipher: any = await import('yt-stream/src/stream/decipher.js') + + const info = await dl.getInfo(query) + + info.formats = await decipher?.format_decipher(info.formats, info.html5player) + + // @ts-ignore The lib did not provide ts support + const url = info.formats.filter((val) => val.mimeType.startsWith('audio') && val.audioQuality !== "AUDIO_QUALITY_LOW").map((val) => val.url) as Array + + if(url.length !== 0) return url[0] + + // @ts-ignore The lib did not provide ts support + return info.formats.filter(val => val.mimeType.startsWith("audio")).map(val => val.url)[0] as string } }; } else { diff --git a/yarn.lock b/yarn.lock index 70cb756d8..361816cac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -167,6 +167,7 @@ __metadata: soundcloud-scraper: ^5.0.3 spotify-url-info: ^3.2.3 youtube-sr: ^4.3.4 + yt-stream: ^1.4.5 ytdl-core: ^4.11.2 languageName: unknown linkType: soft @@ -269,7 +270,7 @@ __metadata: languageName: node linkType: hard -"@discordjs/voice@npm:^0.16.0": +"@discordjs/voice@npm:^0.16.0, @discordjs/voice@npm:latest": version: 0.16.0 resolution: "@discordjs/voice@npm:0.16.0" dependencies: @@ -282,19 +283,6 @@ __metadata: languageName: node linkType: hard -"@discordjs/voice@npm:latest": - version: 0.14.0 - resolution: "@discordjs/voice@npm:0.14.0" - dependencies: - "@types/ws": ^8.5.3 - discord-api-types: ^0.37.20 - prism-media: ^1.3.4 - tslib: ^2.4.1 - ws: ^8.11.0 - checksum: baa68a324f8c7b4a7863a966e7d10a01a4df93aa68800f867e7a6fef016fcd16306ff5a562674884192b0e6538e53e8404d114a7c9781f0637c8e0dea3bca368 - languageName: node - linkType: hard - "@emotion/babel-plugin@npm:^11.10.5": version: 11.10.5 resolution: "@emotion/babel-plugin@npm:11.10.5" @@ -2560,13 +2548,6 @@ __metadata: languageName: node linkType: hard -"discord-api-types@npm:^0.37.20": - version: 0.37.35 - resolution: "discord-api-types@npm:0.37.35" - checksum: 0a65234eefb9675c6faf82f42be6b0a4ee75bf8b2c901eecefea6ca539cd4e2a501b7fc195415884912fdb5040c98727dbd0c5a1f6bc15951948be37d1be162b - languageName: node - linkType: hard - "discord-api-types@npm:^0.37.37": version: 0.37.37 resolution: "discord-api-types@npm:0.37.37" @@ -7540,7 +7521,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^2.0.0, tslib@npm:^2.4.1, tslib@npm:^2.5.0": +"tslib@npm:^2.0.0, tslib@npm:^2.5.0": version: 2.5.0 resolution: "tslib@npm:2.5.0" checksum: ae3ed5f9ce29932d049908ebfdf21b3a003a85653a9a140d614da6b767a93ef94f460e52c3d787f0e4f383546981713f165037dc2274df212ea9f8a4541004e1 @@ -8277,21 +8258,6 @@ __metadata: languageName: node linkType: hard -"ws@npm:^8.11.0": - version: 8.12.1 - resolution: "ws@npm:8.12.1" - peerDependencies: - bufferutil: ^4.0.1 - utf-8-validate: ">=5.0.2" - peerDependenciesMeta: - bufferutil: - optional: true - utf-8-validate: - optional: true - checksum: 97301c1c4d838fc81bd413f370f75c12aabe44527b31323b761eab3043a9ecb7e32ffd668548382c9a6a5ad3a1c3a9249608e8338e6b939f2f9540f1e21970b5 - languageName: node - linkType: hard - "ws@npm:^8.13.0": version: 8.13.0 resolution: "ws@npm:8.13.0" @@ -8385,6 +8351,13 @@ __metadata: languageName: node linkType: hard +"yt-stream@npm:^1.4.5": + version: 1.4.5 + resolution: "yt-stream@npm:1.4.5" + checksum: 561d9eef3447cbb7f28792112ca44518a5178479db45c8bc2d7488c042fa18c317d5a589baae66aa5c417d24a1030becfe7b2f522153130c61c3eda1f1549eed + languageName: node + linkType: hard + "ytdl-core@npm:^4.11.2": version: 4.11.2 resolution: "ytdl-core@npm:4.11.2"