From 2c78d893cf08d7530c922589a7aac5f34df8a204 Mon Sep 17 00:00:00 2001 From: Fafa <87046111+Faf4a@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:46:06 +0200 Subject: [PATCH] 1.2.0 (#22) --- lib/newstruct/manager.d.ts | 2 +- lib/newstruct/manager.js | 145 +++++++-- lib/newstruct/manager.js.map | 2 +- lib/typings/interfaces.d.ts | 10 + package-lock.json | 379 ++++++++++++++++++++++- package.json | 9 +- src/newstruct/manager.ts | 568 +++++++++++++++++++++++------------ src/typings/interfaces.ts | 11 + 8 files changed, 889 insertions(+), 237 deletions(-) diff --git a/lib/newstruct/manager.d.ts b/lib/newstruct/manager.d.ts index b3724b9..44357cf 100755 --- a/lib/newstruct/manager.d.ts +++ b/lib/newstruct/manager.d.ts @@ -21,7 +21,7 @@ export declare class Manager extends TypedEmitter { spotifyApi: SpotifyWebApi; constructor(config?: ManagerConfigurations); static defaultConfig(): ManagerConfigurations; - joinVc({ type, voiceChannel, selfDeaf, selfMute, adapter }: { + joinVc({ type, voiceChannel, selfDeaf, selfMute, adapter, }: { type: AudioPLayerOptions["type"]; voiceChannel: VoiceBasedChannel; selfDeaf?: boolean; diff --git a/lib/newstruct/manager.js b/lib/newstruct/manager.js index 7684fb3..f0c5b54 100755 --- a/lib/newstruct/manager.js +++ b/lib/newstruct/manager.js @@ -19,6 +19,8 @@ const audioPlayer_1 = require("./audioPlayer"); const soundcloud_downloader_1 = __importDefault(require("soundcloud-downloader")); const undici_1 = require("undici"); const enums_1 = require("../typings/enums"); +const jsdom_1 = require("jsdom"); +const bgutils_js_1 = require("bgutils-js"); const fs_1 = require("fs"); const path_1 = require("path"); class Manager extends index_1.TypedEmitter { @@ -36,17 +38,82 @@ class Manager extends index_1.TypedEmitter { if (config.searchOptions?.youtubegl) { ytoptions.cookie = config.searchOptions?.youtubegl ?? "US"; } + if (config.searchOptions?.youtubeToken) { + const requestKey = "O43z0dpjhgX20SCx4KAo"; + /* + * This function generates a YouTube PoToken using BotGuard. + * https://github.com/LuanRT/BgUtils/blob/main/examples/node/main.mjs + * + */ + async function generateYoutubePoToken() { + const visitorData = youtubei_js_1.Proto.encodeVisitorData(youtubei_js_1.Utils.generateRandomString(11), Math.floor(Date.now() / 1000)); + const dom = new jsdom_1.JSDOM(); + globalThis.window = dom.window; + globalThis.document = dom.window.document; + const bgConfig = { + fetch: (url, options) => (0, undici_1.fetch)(url, options), + globalObj: globalThis, + identity: visitorData, + requestKey, + }; + // @ts-expect-error + return bgutils_js_1.BG.Challenge.create(bgConfig) + .then((challenge) => { + if (!challenge) + throw new Error("[@aoijs/aoi.music]: Could not get challenge, remove the youtubeToken option if this error persists"); + if (challenge.script) { + const script = challenge.script.find((sc) => sc !== null); + if (script) + new Function(script)(); + } + else { + console.warn("[@aoijs/aoi.music]: Failed to load BotGuard."); + } + return bgutils_js_1.BG.PoToken.generate({ + program: challenge.challenge, + globalName: challenge.globalName, + // @ts-ignore + bgConfig, + }); + }) + .then((poToken) => { + const authPath = (0, path_1.join)(__dirname, "./credentials.json"); + if (!(0, fs_1.existsSync)(authPath)) { + (0, fs_1.writeFileSync)(authPath, "{}"); + } + const credentials = JSON.parse((0, fs_1.readFileSync)(authPath, "utf-8")); + credentials.poToken = poToken; + credentials.visitorData = visitorData; + (0, fs_1.writeFileSync)(authPath, JSON.stringify(credentials)); + if (config.devOptions?.debug) { + console.log("#DEBUG PoToken:", poToken); + console.log("#DEBUG VisitorData:", visitorData); + } + ytoptions.potoken = { token: poToken, visitorData }; + }) + .catch((error) => { + console.error("[@aoijs/aoi.music]: Failed to generate YouTube PoToken:", error); + }); + } + generateYoutubePoToken(); + } + const youtubeOptions = { + cache: new youtubei_js_1.UniversalCache(true), + }; + if (ytoptions.potoken?.token && ytoptions.potoken?.visitorData) { + youtubeOptions.po_token = ytoptions.potoken.token; + youtubeOptions.visitor_data = ytoptions.potoken.visitorData; + } this.platforms = { - youtube: youtubei_js_1.Innertube.create({ - cache: new youtubei_js_1.UniversalCache(true) - }), + youtube: youtubei_js_1.Innertube.create(youtubeOptions), soundcloud: soundcloud_downloader_1.default, - spotify: (0, spotify_url_info_1.default)(undici_1.fetch) + spotify: (0, spotify_url_info_1.default)(undici_1.fetch), }; - if (config.searchOptions?.spotifyAuth?.clientId && config.searchOptions?.spotifyAuth?.clientSecret) { + if (config.searchOptions?.spotifyAuth?.clientId && + config.searchOptions?.spotifyAuth?.clientSecret) { this.spotifyApi = new spotify_web_api_node_1.default({ clientId: config.searchOptions?.spotifyAuth?.clientId, - clientSecret: config.searchOptions?.spotifyAuth?.clientSecret + clientSecret: config.searchOptions?.spotifyAuth?.clientSecret, }); this.spotifyApi.clientCredentialsGrant().then((data) => { this.spotifyApi.setAccessToken(data.body.access_token); @@ -64,27 +131,44 @@ class Manager extends index_1.TypedEmitter { this.platforms.youtube.then(async (yt) => { // should be inside of node_modules const authPath = (0, path_1.join)(__dirname, "./credentials.json"); + let authData = {}; + if ((0, fs_1.existsSync)(authPath)) { + const fileContent = (0, fs_1.readFileSync)(authPath, "utf8"); + authData = JSON.parse(fileContent); + } yt.session.on("auth-pending", (data) => { console.log(`[@aoijs/aoi.music]: Sign in pending: visit ${data.verification_url} and enter ${data.user_code} to sign in.`); }); + const updateCredentials = (credentials) => { + const current = JSON.parse((0, fs_1.readFileSync)(authPath, "utf-8")); + const { visitorData, poToken } = current; + const newCredentials = { visitorData, poToken, ...credentials }; + (0, fs_1.writeFileSync)(authPath, JSON.stringify(newCredentials)); + }; yt.session.on("auth", ({ credentials }) => { yt.session.oauth.cacheCredentials(); - (0, fs_1.writeFileSync)(authPath, JSON.stringify(credentials)); + updateCredentials(credentials); console.log("[@aoijs/aoi.music]: Successfully signed in."); }); yt.session.on("update-credentials", ({ credentials }) => { yt.session.oauth.cacheCredentials(); - (0, fs_1.writeFileSync)(authPath, JSON.stringify(credentials)); + updateCredentials(credentials); }); - if ((0, fs_1.existsSync)(authPath)) { + // check if access_token exists in file, if not skip to signin + if ((0, fs_1.existsSync)(authPath) && + JSON.parse((0, fs_1.readFileSync)(authPath, "utf-8")).access_token) { try { const credentials = JSON.parse((0, fs_1.readFileSync)(authPath, "utf-8")); + // remove unneeded data + delete credentials.visitorData; + delete credentials.poToken; console.log("[@aoijs/aoi.music]: Attempting to sign in with cached credentials."); await yt.session.signIn(credentials); } catch { console.warn("[@aoijs/aoi.music]: Failed to sign in with cached credentials, please reauthenticate."); - (0, fs_1.unlinkSync)(authPath); + const { visitorData, poToken } = JSON.parse((0, fs_1.readFileSync)(authPath, "utf-8")); + (0, fs_1.writeFileSync)(authPath, JSON.stringify({ visitorData, poToken }, null, 2)); yt.session.oauth.removeCache(); await yt.session.signIn(); } @@ -98,7 +182,7 @@ class Manager extends index_1.TypedEmitter { static defaultConfig() { return { devOptions: { - debug: false + debug: false, }, searchOptions: { soundcloudClientId: undefined, @@ -108,25 +192,25 @@ class Manager extends index_1.TypedEmitter { youtubeClient: "TV_EMBEDDED", spotifyAuth: { clientId: undefined, - clientSecret: undefined - } + clientSecret: undefined, + }, }, requestOptions: { offsetTimeout: 500, soundcloudLikeTrackLimit: -1, youtubePlaylistLimit: -1, - spotifyPlaylistLimit: -1 - } + spotifyPlaylistLimit: -1, + }, }; } - async joinVc({ type = "default", voiceChannel, selfDeaf = true, selfMute = false, adapter }) { + async joinVc({ type = "default", voiceChannel, selfDeaf = true, selfMute = false, adapter, }) { const data = { channelId: voiceChannel.id, guildId: voiceChannel.guild.id, selfDeaf, selfMute, adapterCreator: (adapter ? adapter : voiceChannel.guild?.voiceAdapterCreator ?? adapter), - group: voiceChannel.client.user.id + group: voiceChannel.client.user.id, }; const connection = (0, voice_1.joinVoiceChannel)(data); connection.on("error", console.error); @@ -137,7 +221,7 @@ class Manager extends index_1.TypedEmitter { connection, voiceChannel: voiceChannel.id, manager: this, - debug: this.configs.devOptions?.debug ?? false + debug: this.configs.devOptions?.debug ?? false, })); if (this.configs.devOptions?.debug) { console.log(`#DEBUG:\n Class -> Manager \n Method -> joinVc \n Message -> Joined Voice Channel ${voiceChannel.name} in Guild ${voiceChannel.guild.name}`); @@ -156,7 +240,7 @@ class Manager extends index_1.TypedEmitter { if (type === enums_1.PlatformType.Youtube) { const yt = await this.platforms.youtube; const res = await yt.search(query, { - type: "video" + type: "video", }); return res.videos.slice(0, limit); } @@ -166,13 +250,13 @@ class Manager extends index_1.TypedEmitter { query, limit, offset: 0, - resourceType: "tracks" + resourceType: "tracks", }); return res.collection; } else if (type === enums_1.PlatformType.Spotify) { const res = await this.spotifyApi.searchTracks(query, { - limit + limit, }); return res.body.tracks.items; } @@ -192,19 +276,28 @@ class Manager extends index_1.TypedEmitter { } exports.Manager = Manager; _Manager_instances = new WeakSet(), _Manager_validateConfig = function _Manager_validateConfig(config) { - if (config.requestOptions?.offsetTimeout && (typeof config.requestOptions.offsetTimeout !== "number" || config.requestOptions.offsetTimeout < 0)) { + if (config.requestOptions?.offsetTimeout && + (typeof config.requestOptions.offsetTimeout !== "number" || + config.requestOptions.offsetTimeout < 0)) { throw new Error(`Invalid Time Provided in ManagerConfig#requestOptions['offsetTimeout']`); } - else if (config.requestOptions?.soundcloudLikeTrackLimit && (typeof config.requestOptions.soundcloudLikeTrackLimit !== "number" || config.requestOptions.soundcloudLikeTrackLimit < -1)) { + else if (config.requestOptions?.soundcloudLikeTrackLimit && + (typeof config.requestOptions.soundcloudLikeTrackLimit !== "number" || + config.requestOptions.soundcloudLikeTrackLimit < -1)) { throw new Error(`Invalid Limit Provided in ManagerConfig#requestOptions['soundcloudLikeTrackLimit']`); } - else if (config.requestOptions?.youtubePlaylistLimit && (typeof config.requestOptions.youtubePlaylistLimit !== "number" || config.requestOptions.youtubePlaylistLimit < -1)) { + else if (config.requestOptions?.youtubePlaylistLimit && + (typeof config.requestOptions.youtubePlaylistLimit !== "number" || + config.requestOptions.youtubePlaylistLimit < -1)) { throw new Error(`Invalid Limit Provided in ManagerConfig#requestOptions['youtubePlaylistLimit']`); } - else if (config.requestOptions?.spotifyPlaylistLimit && (typeof config.requestOptions.spotifyPlaylistLimit !== "number" || config.requestOptions.spotifyPlaylistLimit < -1)) { + else if (config.requestOptions?.spotifyPlaylistLimit && + (typeof config.requestOptions.spotifyPlaylistLimit !== "number" || + config.requestOptions.spotifyPlaylistLimit < -1)) { throw new Error(`Invalid Limit Provided in ManagerConfig#requestOptions['spotifyPlaylistLimit']`); } - else if (config.devOptions?.debug && typeof config.devOptions.debug !== "boolean") { + else if (config.devOptions?.debug && + typeof config.devOptions.debug !== "boolean") { throw new Error(`Invalid Debug Option Provided in ManagerConfig#devOptions['debug']`); } if (config.devOptions?.debug) { diff --git a/lib/newstruct/manager.js.map b/lib/newstruct/manager.js.map index ee54f16..18a0b5e 100755 --- a/lib/newstruct/manager.js.map +++ b/lib/newstruct/manager.js.map @@ -1 +1 @@ -{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/newstruct/manager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wEAAgD;AAChD,gFAAiD;AACjD,4CAAsH;AAEtH,wDAA4D;AAC5D,6CAAwD;AAGxD,+CAA4C;AAC5C,kFAAyC;AAEzC,mCAA+B;AAC/B,4CAA4D;AAG5D,2BAAyE;AACzE,+BAA4B;AAE5B,MAAa,OAAQ,SAAQ,oBAA2B;IAOpD,YAAY,MAA8B;QACtC,KAAK,EAAE,CAAC;;QAJZ,YAAO,GAAwC,IAAI,GAAG,EAAkC,CAAC;QAKrF,uBAAA,IAAI,mDAAgB,MAApB,IAAI,EAAiB,MAAM,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,MAAM,SAAS,GAIX,EAAE,CAAC;QACP,IAAI,MAAM,CAAC,aAAa,EAAE,aAAa,EAAE,CAAC;YACtC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC;QAC3D,CAAC;QACD,IAAI,MAAM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AAM,CAAC,cAAc,CAAC,oBAAoB,GAAG,CAAC,CAAC,CAAC,EAClD,CAAC;QACD,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;IACJ,CAAC;SAAM,IACL,MAAM,CAAC,UAAU,EAAE,KAAK;QACxB,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,KAAK,SAAS,EAC5C,CAAC;QACD,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/lib/typings/interfaces.d.ts b/lib/typings/interfaces.d.ts index 05fa556..5734fec 100755 --- a/lib/typings/interfaces.d.ts +++ b/lib/typings/interfaces.d.ts @@ -15,6 +15,7 @@ export interface ManagerConfigurations { youtubeAuth?: boolean; youtubegl?: string; youtubeClient?: "WEB" | "ANDROID" | "YTMUSIC_ANDROID" | "YTMUSIC" | "YTSTUDIO_ANDROID" | "TV_EMBEDDED"; + youtubeToken?: boolean; }; requestOptions?: { offsetTimeout?: number; @@ -23,6 +24,15 @@ export interface ManagerConfigurations { spotifyPlaylistLimit?: number; }; } +export interface Credentials { + visitorData: string; + poToken: string; + access_token?: string; + refresh_token?: string; + scope?: string; + token_type?: string; + expiry_date?: string; +} export interface AudioPLayerOptions { type: "default" | "fonly" | "bidirect"; connection: VoiceConnection; diff --git a/package-lock.json b/package-lock.json index bcc45b4..5899eaf 100755 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,21 @@ { "name": "@aoijs/aoi.music", - "version": "1.0.2", + "version": "1.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@aoijs/aoi.music", - "version": "1.0.2", + "version": "1.1.1", "license": "Apache-2.0", "dependencies": { "@discordjs/voice": "^0.17.0", "@ffprobe-installer/ffprobe": "^2.1.2", + "bgutils-js": "^1.0.1", "discord.js": "^14.15.3", "get-audio-duration": "^4.0.1", "hidefile": "^3.0.0", + "jsdom": "^24.1.1", "prism-media": "^1.3.5", "soundcloud-downloader": "^1.0.0", "soundcloud-key-fetch": "^1.0.13", @@ -24,7 +26,7 @@ "tweetnacl": "^1.0.3", "undici": "^6.19.5", "youtube-scrapper": "^1.4.0", - "youtubei.js": "^10.3.0" + "youtubei.js": "^10.4.0" }, "devDependencies": { "@discordjs/opus": "^0.9.0", @@ -443,6 +445,11 @@ "devOptional": true, "license": "MIT" }, + "node_modules/bgutils-js": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/bgutils-js/-/bgutils-js-1.0.1.tgz", + "integrity": "sha512-onAYO5FZ4fSNOtnC6qxQXNFbR03t/wxBrOAwBpUcw2eUpXgcaUncQ386QTV2RrFTK4KB6vustc7SHeCbM+40fA==" + }, "node_modules/brace-expansion": { "version": "1.1.11", "devOptional": true, @@ -552,6 +559,65 @@ "node": ">= 8" } }, + "node_modules/cssstyle": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-4.0.1.tgz", + "integrity": "sha512-8ZYiJ3A/3OkDd093CBT/0UKDWry7ak4BdPTFP2+QEP7cmhouyq/Up709ASSj2cK02BbZiMgk7kYjZNS4QP5qrQ==", + "dependencies": { + "rrweb-cssom": "^0.6.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/cssstyle/node_modules/rrweb-cssom": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz", + "integrity": "sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==" + }, + "node_modules/data-urls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "dependencies": { + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/data-urls/node_modules/tr46": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.0.0.tgz", + "integrity": "sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/data-urls/node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "engines": { + "node": ">=12" + } + }, + "node_modules/data-urls/node_modules/whatwg-url": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.0.0.tgz", + "integrity": "sha512-1lfMEm2IEr7RIV+f4lUNPOqfFL+pO+Xw3fJSqmjX9AbXcXcYOkCe1P6+9VBZB6n94af16NfZf+sSk0JCBZC9aw==", + "dependencies": { + "tr46": "^5.0.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/debug": { "version": "4.3.4", "license": "MIT", @@ -567,6 +633,11 @@ } } }, + "node_modules/decimal.js": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", + "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==" + }, "node_modules/define-data-property": { "version": "1.1.4", "license": "MIT", @@ -656,7 +727,6 @@ "version": "4.5.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", - "dev": true, "license": "BSD-2-Clause", "engines": { "node": ">=0.12" @@ -970,6 +1040,40 @@ "version": "1.1.0", "license": "ISC" }, + "node_modules/html-encoding-sniffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "dependencies": { + "whatwg-encoding": "^3.1.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/http-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", + "integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==", + "dependencies": { + "agent-base": "^7.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/http-proxy-agent/node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/http-response-object": { "version": "3.0.2", "devOptional": true, @@ -1002,6 +1106,17 @@ "node": ">=10.17.0" } }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/inflight": { "version": "1.0.6", "devOptional": true, @@ -1023,6 +1138,11 @@ "node": ">=8" } }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==" + }, "node_modules/is-stream": { "version": "2.0.1", "license": "MIT", @@ -1048,6 +1168,112 @@ "acorn": "^8.8.0" } }, + "node_modules/jsdom": { + "version": "24.1.1", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-24.1.1.tgz", + "integrity": "sha512-5O1wWV99Jhq4DV7rCLIoZ/UIhyQeDR7wHVyZAHAshbrvZsLs+Xzz7gtwnlJTJDjleiTKh54F4dXrX70vJQTyJQ==", + "dependencies": { + "cssstyle": "^4.0.1", + "data-urls": "^5.0.0", + "decimal.js": "^10.4.3", + "form-data": "^4.0.0", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.5", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.12", + "parse5": "^7.1.2", + "rrweb-cssom": "^0.7.1", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^4.1.4", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0", + "ws": "^8.18.0", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "canvas": "^2.11.2" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, + "node_modules/jsdom/node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/jsdom/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/jsdom/node_modules/https-proxy-agent": { + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz", + "integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==", + "dependencies": { + "agent-base": "^7.0.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/jsdom/node_modules/tr46": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.0.0.tgz", + "integrity": "sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/jsdom/node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "engines": { + "node": ">=12" + } + }, + "node_modules/jsdom/node_modules/whatwg-url": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.0.0.tgz", + "integrity": "sha512-1lfMEm2IEr7RIV+f4lUNPOqfFL+pO+Xw3fJSqmjX9AbXcXcYOkCe1P6+9VBZB6n94af16NfZf+sSk0JCBZC9aw==", + "dependencies": { + "tr46": "^5.0.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/linkify-it": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", @@ -1303,6 +1529,11 @@ "set-blocking": "^2.0.0" } }, + "node_modules/nwsapi": { + "version": "2.2.12", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.12.tgz", + "integrity": "sha512-qXDmcVlZV4XRtKFzddidpfVP4oMSGhga+xdMc25mv8kaLUHtgzCDhUxkrN8exkGdTlLNaXj7CV3GtON7zuGZ+w==" + }, "node_modules/object-assign": { "version": "4.1.1", "devOptional": true, @@ -1350,6 +1581,17 @@ "version": "1.0.1", "devOptional": true }, + "node_modules/parse5": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", + "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", + "dependencies": { + "entities": "^4.4.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/path-is-absolute": { "version": "1.0.1", "devOptional": true, @@ -1397,6 +1639,19 @@ "node": ">=0.4.0" } }, + "node_modules/psl": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" + }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "engines": { + "node": ">=6" + } + }, "node_modules/punycode.js": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", @@ -1420,6 +1675,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" + }, "node_modules/readable-stream": { "version": "3.6.2", "license": "MIT", @@ -1436,6 +1696,11 @@ "version": "0.14.1", "license": "MIT" }, + "node_modules/requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==" + }, "node_modules/rimraf": { "version": "3.0.2", "devOptional": true, @@ -1450,6 +1715,11 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rrweb-cssom": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.7.1.tgz", + "integrity": "sha512-TrEMa7JGdVm0UThDJSx7ddw5nVm3UJS9o9CCIZ72B1vSyEZoziDqBYP3XIoi/12lKrJR8rE3jeFHMok2F/Mnsg==" + }, "node_modules/safe-buffer": { "version": "5.2.1", "funding": [ @@ -1468,10 +1738,26 @@ ], "license": "MIT" }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, "node_modules/sax": { "version": "1.3.0", "license": "ISC" }, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dependencies": { + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" + } + }, "node_modules/semver": { "version": "7.6.2", "license": "ISC", @@ -1657,6 +1943,11 @@ "node": ">= 7.0.0" } }, + "node_modules/symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==" + }, "node_modules/tar": { "version": "6.2.1", "devOptional": true, @@ -1677,6 +1968,20 @@ "version": "2.1.0", "license": "MIT" }, + "node_modules/tough-cookie": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.4.tgz", + "integrity": "sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag==", + "dependencies": { + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/tr46": { "version": "0.0.3", "devOptional": true, @@ -1791,15 +2096,62 @@ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.11.1.tgz", "integrity": "sha512-mIDEX2ek50x0OlRgxryxsenE5XaQD4on5U2inY7RApK3SOJpofyw7uW2AyfMKkhAxXIceo2DeWGVGwyvng1GNQ==" }, + "node_modules/universalify": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", + "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==", + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dependencies": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "license": "MIT" }, + "node_modules/w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/webidl-conversions": { "version": "3.0.1", "devOptional": true, "license": "BSD-2-Clause" }, + "node_modules/whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "engines": { + "node": ">=18" + } + }, "node_modules/whatwg-url": { "version": "5.0.0", "devOptional": true, @@ -1865,6 +2217,19 @@ } } }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "engines": { + "node": ">=18" + } + }, + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==" + }, "node_modules/yallist": { "version": "4.0.0", "devOptional": true, @@ -1899,9 +2264,9 @@ } }, "node_modules/youtubei.js": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-10.3.0.tgz", - "integrity": "sha512-tLmeJCECK2xF2hZZtF2nEqirdKVNLFSDpa0LhTaXY3tngtL7doQXyy7M2CLueramDTlmCnFaW+rctHirTPFaRQ==", + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-10.4.0.tgz", + "integrity": "sha512-FZahkkg5ROyH/FgJ4czy/xDNkqHbJTCUQzumQlnR+2Q7m6HaWghAFWWJUTcexemGuu7t/5EuyQz98eBgKQRMog==", "funding": [ "https://github.com/sponsors/LuanRT" ], diff --git a/package.json b/package.json index be4452a..80de2f8 100755 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "name": "@aoijs/aoi.music", - "version": "1.1.1", + "version": "1.2.0", "description": "Addition of the Music properties and foundation for aoi.js", "author": { "name": "Leref" }, "maintainers": [ - "USERSATOSHI" + "USERSATOSHI", + "faf4a" ], "scripts": { "build": "npx tsc" @@ -33,9 +34,11 @@ "dependencies": { "@discordjs/voice": "^0.17.0", "@ffprobe-installer/ffprobe": "^2.1.2", + "bgutils-js": "^1.0.1", "discord.js": "^14.15.3", "get-audio-duration": "^4.0.1", "hidefile": "^3.0.0", + "jsdom": "^24.1.1", "prism-media": "^1.3.5", "soundcloud-downloader": "^1.0.0", "soundcloud-key-fetch": "^1.0.13", @@ -46,7 +49,7 @@ "tweetnacl": "^1.0.3", "undici": "^6.19.5", "youtube-scrapper": "^1.4.0", - "youtubei.js": "^10.3.0" + "youtubei.js": "^10.4.0" }, "devDependencies": { "@discordjs/opus": "^0.9.0", diff --git a/src/newstruct/manager.ts b/src/newstruct/manager.ts index 552bf77..f94a705 100755 --- a/src/newstruct/manager.ts +++ b/src/newstruct/manager.ts @@ -1,11 +1,21 @@ import sui, { Spotify } from "spotify-url-info"; import SpotifyWebApi from "spotify-web-api-node"; -import { DiscordGatewayAdapterCreator, entersState, joinVoiceChannel, VoiceConnectionStatus } from "@discordjs/voice"; +import { + DiscordGatewayAdapterCreator, + entersState, + joinVoiceChannel, + VoiceConnectionStatus, +} from "@discordjs/voice"; import { Snowflake, VoiceBasedChannel } from "discord.js"; import { TypedEmitter } from "tiny-typed-emitter/lib/index"; -import { Innertube, UniversalCache } from "youtubei.js"; +import { Innertube, UniversalCache, Proto, Utils } from "youtubei.js"; import IT from "youtubei.js"; -import { AudioPLayerOptions, ManagerConfigurations, ManagerEvents } from "../typings/interfaces"; +import { + Credentials, + AudioPLayerOptions, + ManagerConfigurations, + ManagerEvents, +} from "../typings/interfaces"; import { AudioPlayer } from "./audioPlayer"; import scdl from "soundcloud-downloader"; import { SCDL } from "soundcloud-downloader/src"; @@ -13,224 +23,384 @@ import { fetch } from "undici"; import { PlatformType, PluginName } from "../typings/enums"; import { TrackInfo } from "soundcloud-downloader/src/info"; import { Plugin } from "../typings/types"; -import { existsSync, readFileSync, writeFileSync, unlinkSync } from "fs"; +import { JSDOM } from "jsdom"; +import { BG } from "bgutils-js"; +import { existsSync, readFileSync, writeFileSync } from "fs"; import { join } from "path"; export class Manager extends TypedEmitter { - configs: ManagerConfigurations; - players: Map; - platforms: { youtube: Promise; spotify?: Spotify; soundcloud: SCDL }; - plugins: Map> = new Map>(); - spotifyApi: SpotifyWebApi; - - constructor(config?: ManagerConfigurations) { - super(); - this.#validateConfig(config); - this.configs = config ?? Manager.defaultConfig(); - this.players = new Map(); - const ytoptions: { - gl?: string; - cookie?: string; - debug?: boolean; - } = {}; - if (config.searchOptions?.youtubeCookie) { - ytoptions.cookie = config.searchOptions?.youtubeCookie; - } - if (config.searchOptions?.youtubegl) { - ytoptions.cookie = config.searchOptions?.youtubegl ?? "US"; - } - this.platforms = { - youtube: Innertube.create({ - cache: new UniversalCache(true) - }), - soundcloud: scdl, - spotify: sui(fetch) + configs: ManagerConfigurations; + players: Map; + platforms: { youtube: Promise; spotify?: Spotify; soundcloud: SCDL }; + plugins: Map> = new Map< + PluginName, + Plugin + >(); + spotifyApi: SpotifyWebApi; + + constructor(config?: ManagerConfigurations) { + super(); + this.#validateConfig(config); + this.configs = config ?? Manager.defaultConfig(); + this.players = new Map(); + const ytoptions: { + gl?: string; + cookie?: string; + debug?: boolean; + potoken?: { + token?: string; + visitorData?: string; + }; + } = {}; + if (config.searchOptions?.youtubeCookie) { + ytoptions.cookie = config.searchOptions?.youtubeCookie; + } + if (config.searchOptions?.youtubegl) { + ytoptions.cookie = config.searchOptions?.youtubegl ?? "US"; + } + if (config.searchOptions?.youtubeToken) { + const requestKey = "O43z0dpjhgX20SCx4KAo"; + + /* + * This function generates a YouTube PoToken using BotGuard. + * https://github.com/LuanRT/BgUtils/blob/main/examples/node/main.mjs + * + */ + async function generateYoutubePoToken(): Promise { + const visitorData = Proto.encodeVisitorData( + Utils.generateRandomString(11), + Math.floor(Date.now() / 1000) + ); + + const dom = new JSDOM(); + + globalThis.window = dom.window; + globalThis.document = dom.window.document; + + const bgConfig = { + fetch: (url, options) => fetch(url, options), + globalObj: globalThis, + identity: visitorData, + requestKey, }; - if (config.searchOptions?.spotifyAuth?.clientId && config.searchOptions?.spotifyAuth?.clientSecret) { - this.spotifyApi = new SpotifyWebApi({ - clientId: config.searchOptions?.spotifyAuth?.clientId, - clientSecret: config.searchOptions?.spotifyAuth?.clientSecret - }); + // @ts-expect-error + return BG.Challenge.create(bgConfig) + .then((challenge) => { + if (!challenge) + throw new Error( + "[@aoijs/aoi.music]: Could not get challenge, remove the youtubeToken option if this error persists" + ); + + if (challenge.script) { + const script = challenge.script.find((sc) => sc !== null); + if (script) new Function(script)(); + } else { + console.warn("[@aoijs/aoi.music]: Failed to load BotGuard."); + } - this.spotifyApi.clientCredentialsGrant().then((data) => { - this.spotifyApi.setAccessToken(data.body.access_token); + return BG.PoToken.generate({ + program: challenge.challenge, + globalName: challenge.globalName, + // @ts-ignore + bgConfig, }); + }) + .then((poToken) => { + const authPath = join(__dirname, "./credentials.json"); + if (!existsSync(authPath)) { + writeFileSync(authPath, "{}"); + } + const credentials = JSON.parse(readFileSync(authPath, "utf-8")); + credentials.poToken = poToken; + credentials.visitorData = visitorData; + writeFileSync(authPath, JSON.stringify(credentials)); + if (config.devOptions?.debug) { + console.log("#DEBUG PoToken:", poToken); + console.log("#DEBUG VisitorData:", visitorData); + } + ytoptions.potoken = { token: poToken, visitorData }; + }) + .catch((error) => { + console.error( + "[@aoijs/aoi.music]: Failed to generate YouTube PoToken:", + error + ); + }); + } - setInterval(() => { - this.spotifyApi.clientCredentialsGrant().then((data) => { - this.spotifyApi.setAccessToken(data.body.access_token); - }); - }, 36e5); - } + generateYoutubePoToken(); + } + const youtubeOptions: any = { + cache: new UniversalCache(true), + }; + if (ytoptions.potoken?.token && ytoptions.potoken?.visitorData) { + youtubeOptions.po_token = ytoptions.potoken.token; + youtubeOptions.visitor_data = ytoptions.potoken.visitorData; + } + this.platforms = { + youtube: Innertube.create(youtubeOptions), + soundcloud: scdl, + spotify: sui(fetch), + }; + if ( + config.searchOptions?.spotifyAuth?.clientId && + config.searchOptions?.spotifyAuth?.clientSecret + ) { + this.spotifyApi = new SpotifyWebApi({ + clientId: config.searchOptions?.spotifyAuth?.clientId, + clientSecret: config.searchOptions?.spotifyAuth?.clientSecret, + }); - if (config.searchOptions?.soundcloudClientId) { - this.platforms.soundcloud.setClientID(config.searchOptions.soundcloudClientId); - } - if (config.searchOptions?.youtubeAuth === true) { - this.platforms.youtube.then(async (yt) => { - // should be inside of node_modules - const authPath = join(__dirname, "./credentials.json"); - - yt.session.on("auth-pending", (data) => { - console.log(`[@aoijs/aoi.music]: Sign in pending: visit ${data.verification_url} and enter ${data.user_code} to sign in.`); - }); - - yt.session.on("auth", ({ credentials }) => { - yt.session.oauth.cacheCredentials(); - writeFileSync(authPath, JSON.stringify(credentials)); - console.log("[@aoijs/aoi.music]: Successfully signed in."); - }); - - yt.session.on("update-credentials", ({ credentials }) => { - yt.session.oauth.cacheCredentials(); - writeFileSync(authPath, JSON.stringify(credentials)); - }); - - if (existsSync(authPath)) { - try { - const credentials = JSON.parse(readFileSync(authPath, "utf-8")); - console.log("[@aoijs/aoi.music]: Attempting to sign in with cached credentials."); - await yt.session.signIn(credentials); - } catch { - console.warn("[@aoijs/aoi.music]: Failed to sign in with cached credentials, please reauthenticate."); - unlinkSync(authPath); - yt.session.oauth.removeCache(); - await yt.session.signIn(); - } - } else { - yt.session.signIn(); - } - }); - } + this.spotifyApi.clientCredentialsGrant().then((data) => { + this.spotifyApi.setAccessToken(data.body.access_token); + }); + + setInterval(() => { + this.spotifyApi.clientCredentialsGrant().then((data) => { + this.spotifyApi.setAccessToken(data.body.access_token); + }); + }, 36e5); } - static defaultConfig(): ManagerConfigurations { - return { - devOptions: { - debug: false - }, - searchOptions: { - soundcloudClientId: undefined, - youtubeCookie: undefined, - youtubeAuth: true, - youtubegl: "US", - youtubeClient: "TV_EMBEDDED", - spotifyAuth: { - clientId: undefined, - clientSecret: undefined - } - }, - requestOptions: { - offsetTimeout: 500, - soundcloudLikeTrackLimit: -1, - youtubePlaylistLimit: -1, - spotifyPlaylistLimit: -1 - } - }; + if (config.searchOptions?.soundcloudClientId) { + this.platforms.soundcloud.setClientID( + config.searchOptions.soundcloudClientId + ); } + if (config.searchOptions?.youtubeAuth === true) { + this.platforms.youtube.then(async (yt) => { + // should be inside of node_modules + const authPath = join(__dirname, "./credentials.json"); + let authData = {}; - #validateConfig(config: ManagerConfigurations) { - if (config.requestOptions?.offsetTimeout && (typeof config.requestOptions.offsetTimeout !== "number" || config.requestOptions.offsetTimeout < 0)) { - throw new Error(`Invalid Time Provided in ManagerConfig#requestOptions['offsetTimeout']`); - } else if (config.requestOptions?.soundcloudLikeTrackLimit && (typeof config.requestOptions.soundcloudLikeTrackLimit !== "number" || config.requestOptions.soundcloudLikeTrackLimit < -1)) { - throw new Error(`Invalid Limit Provided in ManagerConfig#requestOptions['soundcloudLikeTrackLimit']`); - } else if (config.requestOptions?.youtubePlaylistLimit && (typeof config.requestOptions.youtubePlaylistLimit !== "number" || config.requestOptions.youtubePlaylistLimit < -1)) { - throw new Error(`Invalid Limit Provided in ManagerConfig#requestOptions['youtubePlaylistLimit']`); - } else if (config.requestOptions?.spotifyPlaylistLimit && (typeof config.requestOptions.spotifyPlaylistLimit !== "number" || config.requestOptions.spotifyPlaylistLimit < -1)) { - throw new Error(`Invalid Limit Provided in ManagerConfig#requestOptions['spotifyPlaylistLimit']`); - } else if (config.devOptions?.debug && typeof config.devOptions.debug !== "boolean") { - throw new Error(`Invalid Debug Option Provided in ManagerConfig#devOptions['debug']`); - } - if (config.devOptions?.debug) { - console.log("Debug Mode Enabled"); + if (existsSync(authPath)) { + const fileContent = readFileSync(authPath, "utf8"); + authData = JSON.parse(fileContent); } - } - async joinVc({ - type = "default", - voiceChannel, - selfDeaf = true, - selfMute = false, - adapter - }: { - type: AudioPLayerOptions["type"]; - voiceChannel: VoiceBasedChannel; - selfDeaf?: boolean; - selfMute?: boolean; - adapter?: any; - }): Promise { - const data = { - channelId: voiceChannel.id, - guildId: voiceChannel.guild.id, - selfDeaf, - selfMute, - adapterCreator: < - DiscordGatewayAdapterCreator // @ts-ignore - >(adapter ? adapter : voiceChannel.guild?.voiceAdapterCreator ?? adapter), - group: voiceChannel.client.user.id + yt.session.on("auth-pending", (data) => { + console.log( + `[@aoijs/aoi.music]: Sign in pending: visit ${data.verification_url} and enter ${data.user_code} to sign in.` + ); + }); + + const updateCredentials = (credentials: Partial) => { + const current: Credentials = JSON.parse(readFileSync(authPath, "utf-8")); + + const { visitorData, poToken } = current; + const newCredentials: Credentials = { visitorData, poToken, ...credentials }; + + writeFileSync(authPath, JSON.stringify(newCredentials)); }; - const connection = joinVoiceChannel(data); - connection.on("error", console.error); - try { - await entersState(connection, VoiceConnectionStatus.Ready, 30000); - this.players.set( - voiceChannel.guildId, - new AudioPlayer({ - type, - connection, - voiceChannel: voiceChannel.id, - manager: this, - debug: this.configs.devOptions?.debug ?? false - }) + + yt.session.on("auth", ({ credentials }) => { + yt.session.oauth.cacheCredentials(); + updateCredentials(credentials); + console.log("[@aoijs/aoi.music]: Successfully signed in."); + }); + + yt.session.on("update-credentials", ({ credentials }) => { + yt.session.oauth.cacheCredentials(); + updateCredentials(credentials); + }); + + // check if access_token exists in file, if not skip to signin + if ( + existsSync(authPath) && + JSON.parse(readFileSync(authPath, "utf-8")).access_token + ) { + try { + const credentials = JSON.parse(readFileSync(authPath, "utf-8")); + // remove unneeded data + delete credentials.visitorData; + delete credentials.poToken; + console.log( + "[@aoijs/aoi.music]: Attempting to sign in with cached credentials." ); - if (this.configs.devOptions?.debug) { - console.log(`#DEBUG:\n Class -> Manager \n Method -> joinVc \n Message -> Joined Voice Channel ${voiceChannel.name} in Guild ${voiceChannel.guild.name}`); - } - return true; - } catch (error) { - connection.destroy(); - if (this.configs.devOptions?.debug) { - console.log(`#DEBUG:\n Class -> Manager \n Method -> joinVc \n Message -> Failed to join Voice Channel ${voiceChannel.name} in Guild ${voiceChannel.guild.name}`); - } - return false; + await yt.session.signIn(credentials); + } catch { + console.warn( + "[@aoijs/aoi.music]: Failed to sign in with cached credentials, please reauthenticate." + ); + const { visitorData, poToken } = JSON.parse( + readFileSync(authPath, "utf-8") + ); + writeFileSync( + authPath, + JSON.stringify({ visitorData, poToken }, null, 2) + ); + yt.session.oauth.removeCache(); + await yt.session.signIn(); + } + } else { + yt.session.signIn(); } + }); } + } - async search(type: T, query: string, limit = 1) { - if (type === PlatformType.Youtube) { - const yt = await this.platforms.youtube; - const res = await yt.search(query, { - type: "video" - }); - return res.videos.slice(0, limit); - } else if (type === PlatformType.SoundCloud) { - const sc = this.platforms.soundcloud; - const res = await sc.search({ - query, - limit, - offset: 0, - resourceType: "tracks" - }); - return res.collection; - } else if (type === PlatformType.Spotify) { - const res = await this.spotifyApi.searchTracks(query, { - limit - }); - return res.body.tracks.items; - } + static defaultConfig(): ManagerConfigurations { + return { + devOptions: { + debug: false, + }, + searchOptions: { + soundcloudClientId: undefined, + youtubeCookie: undefined, + youtubeAuth: true, + youtubegl: "US", + youtubeClient: "TV_EMBEDDED", + spotifyAuth: { + clientId: undefined, + clientSecret: undefined, + }, + }, + requestOptions: { + offsetTimeout: 500, + soundcloudLikeTrackLimit: -1, + youtubePlaylistLimit: -1, + spotifyPlaylistLimit: -1, + }, + }; + } + + #validateConfig(config: ManagerConfigurations) { + if ( + config.requestOptions?.offsetTimeout && + (typeof config.requestOptions.offsetTimeout !== "number" || + config.requestOptions.offsetTimeout < 0) + ) { + throw new Error( + `Invalid Time Provided in ManagerConfig#requestOptions['offsetTimeout']` + ); + } else if ( + config.requestOptions?.soundcloudLikeTrackLimit && + (typeof config.requestOptions.soundcloudLikeTrackLimit !== "number" || + config.requestOptions.soundcloudLikeTrackLimit < -1) + ) { + throw new Error( + `Invalid Limit Provided in ManagerConfig#requestOptions['soundcloudLikeTrackLimit']` + ); + } else if ( + config.requestOptions?.youtubePlaylistLimit && + (typeof config.requestOptions.youtubePlaylistLimit !== "number" || + config.requestOptions.youtubePlaylistLimit < -1) + ) { + throw new Error( + `Invalid Limit Provided in ManagerConfig#requestOptions['youtubePlaylistLimit']` + ); + } else if ( + config.requestOptions?.spotifyPlaylistLimit && + (typeof config.requestOptions.spotifyPlaylistLimit !== "number" || + config.requestOptions.spotifyPlaylistLimit < -1) + ) { + throw new Error( + `Invalid Limit Provided in ManagerConfig#requestOptions['spotifyPlaylistLimit']` + ); + } else if ( + config.devOptions?.debug && + typeof config.devOptions.debug !== "boolean" + ) { + throw new Error( + `Invalid Debug Option Provided in ManagerConfig#devOptions['debug']` + ); } + if (config.devOptions?.debug) { + console.log("Debug Mode Enabled"); + } + } - addPlugin(name: A, plugin: Plugin) { - this.plugins.set(name, plugin); - if (this.configs.devOptions?.debug) { - console.log(`#DEBUG:\n Class -> Manager \n Method -> addPlugin \n Message -> Added Plugin ${plugin.constructor.name} with name : ${name} `); - } + async joinVc({ + type = "default", + voiceChannel, + selfDeaf = true, + selfMute = false, + adapter, + }: { + type: AudioPLayerOptions["type"]; + voiceChannel: VoiceBasedChannel; + selfDeaf?: boolean; + selfMute?: boolean; + adapter?: any; + }): Promise { + const data = { + channelId: voiceChannel.id, + guildId: voiceChannel.guild.id, + selfDeaf, + selfMute, + adapterCreator: < + DiscordGatewayAdapterCreator // @ts-ignore + >(adapter ? adapter : voiceChannel.guild?.voiceAdapterCreator ?? adapter), + group: voiceChannel.client.user.id, + }; + const connection = joinVoiceChannel(data); + connection.on("error", console.error); + try { + await entersState(connection, VoiceConnectionStatus.Ready, 30000); + this.players.set( + voiceChannel.guildId, + new AudioPlayer({ + type, + connection, + voiceChannel: voiceChannel.id, + manager: this, + debug: this.configs.devOptions?.debug ?? false, + }) + ); + if (this.configs.devOptions?.debug) { + console.log( + `#DEBUG:\n Class -> Manager \n Method -> joinVc \n Message -> Joined Voice Channel ${voiceChannel.name} in Guild ${voiceChannel.guild.name}` + ); + } + return true; + } catch (error) { + connection.destroy(); + if (this.configs.devOptions?.debug) { + console.log( + `#DEBUG:\n Class -> Manager \n Method -> joinVc \n Message -> Failed to join Voice Channel ${voiceChannel.name} in Guild ${voiceChannel.guild.name}` + ); + } + return false; } - leaveVc(guildId: string) { - const player = this.players.get(guildId); - player?._destroy(); - this.players.delete(guildId); - return player.options.connection.destroy(); + } + + async search(type: T, query: string, limit = 1) { + if (type === PlatformType.Youtube) { + const yt = await this.platforms.youtube; + const res = await yt.search(query, { + type: "video", + }); + return res.videos.slice(0, limit); + } else if (type === PlatformType.SoundCloud) { + const sc = this.platforms.soundcloud; + const res = await sc.search({ + query, + limit, + offset: 0, + resourceType: "tracks", + }); + return res.collection; + } else if (type === PlatformType.Spotify) { + const res = await this.spotifyApi.searchTracks(query, { + limit, + }); + return res.body.tracks.items; + } + } + + addPlugin(name: A, plugin: Plugin) { + this.plugins.set(name, plugin); + if (this.configs.devOptions?.debug) { + console.log( + `#DEBUG:\n Class -> Manager \n Method -> addPlugin \n Message -> Added Plugin ${plugin.constructor.name} with name : ${name} ` + ); } + } + leaveVc(guildId: string) { + const player = this.players.get(guildId); + player?._destroy(); + this.players.delete(guildId); + return player.options.connection.destroy(); + } } diff --git a/src/typings/interfaces.ts b/src/typings/interfaces.ts index c31dabb..793714b 100755 --- a/src/typings/interfaces.ts +++ b/src/typings/interfaces.ts @@ -16,6 +16,7 @@ export interface ManagerConfigurations { youtubeAuth?: boolean; youtubegl?: string; youtubeClient?: "WEB" | "ANDROID" | "YTMUSIC_ANDROID" | "YTMUSIC" | "YTSTUDIO_ANDROID" | "TV_EMBEDDED"; + youtubeToken?: boolean; }; requestOptions?: { offsetTimeout?: number; @@ -25,6 +26,16 @@ export interface ManagerConfigurations { }; } +export interface Credentials { + visitorData: string; + poToken: string; + access_token?: string; + refresh_token?: string; + scope?: string; + token_type?: string; + expiry_date?: string; +} + export interface AudioPLayerOptions { type: "default" | "fonly" | "bidirect"; connection: VoiceConnection;