diff --git a/package.json b/package.json index 3ab89ff..5aba5a9 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "jsdom": "^27.0.0", "murmurhash": "^2.0.1", "node-ffprobe": "^3.0.0", - "proxy-agent": "^6.5.0", "sh": "github:Cynosphere/sh", "sharp": "^0.34.3", "sqlite3": "^5.1.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d007bf6..c7ee5e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,9 +47,6 @@ importers: node-ffprobe: specifier: ^3.0.0 version: 3.0.0 - proxy-agent: - specifier: ^6.5.0 - version: 6.5.0 sh: specifier: github:Cynosphere/sh version: https://codeload.github.com/Cynosphere/sh/tar.gz/ea34c6dbaee8d4e8fb516230b164c97a18d5db81 @@ -712,9 +709,6 @@ packages: resolution: {integrity: sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==} engines: {node: '>= 6'} - '@tootallnate/quickjs-emscripten@0.23.0': - resolution: {integrity: sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==} - '@types/keyv@3.1.4': resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} @@ -788,20 +782,12 @@ packages: resolution: {integrity: sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==} engines: {node: '>=0.8'} - ast-types@0.13.4: - resolution: {integrity: sha512-x1FCFnFifvYDDzTaLII71vG5uvDwgtmDTEVWAxrgeiR8VjMONcCXJx7E+USjDtHlwFmt9MysbqgF9b9Vjr6w+w==} - engines: {node: '>=4'} - balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} - basic-ftp@5.0.5: - resolution: {integrity: sha512-4Bcg1P8xhUuqcii/S0Z9wiHIrQVPMermM1any+MX5GeGD7faD3/msQUDGLol9wOcz4/jbg/WJnGqoJF6LiBdtg==} - engines: {node: '>=10.0.0'} - bcrypt-pbkdf@1.0.2: resolution: {integrity: sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==} @@ -917,10 +903,6 @@ packages: resolution: {integrity: sha512-jRFi8UDGo6j+odZiEpjazZaWqEal3w/basFjQHQEwVtZJGDpxbH1MeYluwCS8Xq5wmLJooDlMgvVarmWfGM44g==} engines: {node: '>=0.10'} - data-uri-to-buffer@6.0.2: - resolution: {integrity: sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==} - engines: {node: '>= 14'} - data-urls@6.0.0: resolution: {integrity: sha512-BnBS08aLUM+DKamupXs3w2tJJoqU+AkaE/+6vQxi/G/DPmIZFJJp9Dkb1kM03AZx8ADehDUZgsNxju3mPXZYIA==} engines: {node: '>=20'} @@ -948,10 +930,6 @@ packages: deep-is@0.1.4: resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} - degenerator@5.0.1: - resolution: {integrity: sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ==} - engines: {node: '>= 14'} - delegates@1.0.0: resolution: {integrity: sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==} @@ -1000,11 +978,6 @@ packages: resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==} engines: {node: '>=10'} - escodegen@2.1.0: - resolution: {integrity: sha512-2NlIDTwUWJN0mRPQOdtQBzbUHvdGY2P1VXSyU83Q3xKxM7WHX2Ql8dKq782Q9TgQUNOLEzEYu9bzLNj1q88I5w==} - engines: {node: '>=6.0'} - hasBin: true - eslint-scope@7.2.0: resolution: {integrity: sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1022,11 +995,6 @@ packages: resolution: {integrity: sha512-5yxtHSZXRSW5pvv3hAlXM5+/Oswi1AUFqBmbibKb5s6bp3rGIDkyXU6xCoyuuLhijr4SFwPrXRoZjz0AZDN9tg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - esprima@4.0.1: - resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==} - engines: {node: '>=4'} - hasBin: true - esquery@1.5.0: resolution: {integrity: sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==} engines: {node: '>=0.10'} @@ -1111,10 +1079,6 @@ packages: resolution: {integrity: sha512-GlhdIUuVakc8SJ6kK0zAFbiGzRFzNnY4jUuEbV9UROo4Y+0Ny4fjvcZFVTeDA4odpFyOQzaw6hXukJSq/f28sQ==} engines: {node: '>=4'} - get-uri@6.0.5: - resolution: {integrity: sha512-b1O07XYq8eRuVzBNgJLstU6FYc1tS6wnMtF1I1D9lE8LxZSOGZ7LhxN54yPP6mGw5f2CkXY2BQUL9Fx41qvcIg==} - engines: {node: '>= 14'} - getpass@0.1.7: resolution: {integrity: sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==} @@ -1348,10 +1312,6 @@ packages: resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} engines: {node: '>=10'} - lru-cache@7.18.3: - resolution: {integrity: sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==} - engines: {node: '>=12'} - make-fetch-happen@9.1.0: resolution: {integrity: sha512-+zopwDy7DNknmwPQplem5lAZX/eCOzSvSNNcSKm5eVwTkOBzoktEfXsa9L23J/GIRhxRsaxzkPEhrJEpE2F4Gg==} engines: {node: '>= 10'} @@ -1447,10 +1407,6 @@ packages: resolution: {integrity: sha512-myRT3DiWPHqho5PrJaIRyaMv2kgYf0mUVgBNOYMuCH5Ki1yEiQaf/ZJuQ62nvpc44wL5WDbTX7yGJi1Neevw8w==} engines: {node: '>= 0.6'} - netmask@2.0.2: - resolution: {integrity: sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg==} - engines: {node: '>= 0.4.0'} - node-abi@3.75.0: resolution: {integrity: sha512-OhYaY5sDsIka7H7AtijtI9jwGYLyl29eQn/W623DiN/MIv5sUqc4g7BIDThX+gb7di9f6xK02nkp8sdfFWZLTg==} engines: {node: '>=10'} @@ -1511,14 +1467,6 @@ packages: resolution: {integrity: sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==} engines: {node: '>=10'} - pac-proxy-agent@7.2.0: - resolution: {integrity: sha512-TEB8ESquiLMc0lV8vcd5Ql/JAKAoyzHFXaStwjkzpOpC5Yv+pIzLfHvjTSdf3vpa2bMiUQrg9i6276yn8666aA==} - engines: {node: '>= 14'} - - pac-resolver@7.0.1: - resolution: {integrity: sha512-5NPgf87AT2STgwa2ntRMr45jTKrYBGkVU36yT0ig/n/GMAa3oPqhZfIQ2kMEimReg0+t9kZViDVZ83qfVUlckg==} - engines: {node: '>= 14'} - pako@1.0.11: resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==} @@ -1613,13 +1561,6 @@ packages: resolution: {integrity: sha512-y+WKFlBR8BGXnsNlIHFGPZmyDf3DFMoLhaflAnyZgV6rG6xu+JwesTo2Q9R6XwYmtmwAFCkAk3e35jEdoeh/3g==} engines: {node: '>=10'} - proxy-agent@6.5.0: - resolution: {integrity: sha512-TmatMXdr2KlRiA2CyDu8GqR8EjahTG3aY3nXjdzFyoZbmB8hrBsTyMezhULIXKnC0jpfjlmiZ3+EaCzoInSu/A==} - engines: {node: '>= 14'} - - proxy-from-env@1.1.0: - resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} - pump@3.0.3: resolution: {integrity: sha512-todwxLMY7/heScKmntwQG8CXVkWUOdYxIvY2s0VWAAMh/nd8SoYiRaKjlr7+iCs984f2P8zvrfWcDDYVb73NfA==} @@ -1732,10 +1673,6 @@ packages: resolution: {integrity: sha512-a6KW9G+6B3nWZ1yB8G7pJwL3ggLy1uTzKAgCb7ttblwqdz9fMGJUuTy3uFzEP48FAs9FLILlmzDlE2JJhVQaXQ==} engines: {node: '>= 10'} - socks-proxy-agent@8.0.5: - resolution: {integrity: sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw==} - engines: {node: '>= 14'} - socks@2.8.7: resolution: {integrity: sha512-HLpt+uLy/pxB+bum/9DzAgiKS8CX1EvbWxI4zlmgGCExImLdiad2iCwXT5Z4c9c3Eq8rP2318mPW2c+QbtjK8A==} engines: {node: '>= 10.0.0', npm: '>= 3.0.0'} @@ -1744,10 +1681,6 @@ packages: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} - source-map@0.6.1: - resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} - engines: {node: '>=0.10.0'} - sqlite3@5.1.7: resolution: {integrity: sha512-GGIyOiFaG+TUra3JIfkI/zGP8yZYLPQ0pl1bH+ODjiX57sPhrLU5sQJn1y9bDKZUFYkX1crlrPfSYt0BKKdkog==} @@ -2724,8 +2657,6 @@ snapshots: '@tootallnate/once@1.1.2': optional: true - '@tootallnate/quickjs-emscripten@0.23.0': {} - '@types/keyv@3.1.4': dependencies: '@types/node': 18.16.0 @@ -2799,16 +2730,10 @@ snapshots: assert-plus@1.0.0: {} - ast-types@0.13.4: - dependencies: - tslib: 2.8.1 - balanced-match@1.0.2: {} base64-js@1.5.1: {} - basic-ftp@5.0.5: {} - bcrypt-pbkdf@1.0.2: dependencies: tweetnacl: 0.14.5 @@ -2952,8 +2877,6 @@ snapshots: dependencies: assert-plus: 1.0.0 - data-uri-to-buffer@6.0.2: {} - data-urls@6.0.0: dependencies: whatwg-mimetype: 4.0.0 @@ -2973,12 +2896,6 @@ snapshots: deep-is@0.1.4: {} - degenerator@5.0.1: - dependencies: - ast-types: 0.13.4 - escodegen: 2.1.0 - esprima: 4.0.1 - delegates@1.0.0: optional: true @@ -3028,14 +2945,6 @@ snapshots: escape-string-regexp@4.0.0: {} - escodegen@2.1.0: - dependencies: - esprima: 4.0.1 - estraverse: 5.3.0 - esutils: 2.0.3 - optionalDependencies: - source-map: 0.6.1 - eslint-scope@7.2.0: dependencies: esrecurse: 4.3.0 @@ -3094,8 +3003,6 @@ snapshots: acorn-jsx: 5.3.2(acorn@8.8.2) eslint-visitor-keys: 3.4.0 - esprima@4.0.1: {} - esquery@1.5.0: dependencies: estraverse: 5.3.0 @@ -3174,14 +3081,6 @@ snapshots: get-stream@3.0.0: {} - get-uri@6.0.5: - dependencies: - basic-ftp: 5.0.5 - data-uri-to-buffer: 6.0.2 - debug: 4.3.4 - transitivePeerDependencies: - - supports-color - getpass@0.1.7: dependencies: assert-plus: 1.0.0 @@ -3324,7 +3223,8 @@ snapshots: ini@1.3.8: {} - ip-address@10.0.1: {} + ip-address@10.0.1: + optional: true is-arrayish@0.3.2: {} @@ -3466,8 +3366,6 @@ snapshots: yallist: 4.0.0 optional: true - lru-cache@7.18.3: {} - make-fetch-happen@9.1.0: dependencies: agentkeepalive: 4.6.0 @@ -3570,8 +3468,6 @@ snapshots: negotiator@0.6.4: optional: true - netmask@2.0.2: {} - node-abi@3.75.0: dependencies: semver: 7.7.2 @@ -3647,24 +3543,6 @@ snapshots: aggregate-error: 3.1.0 optional: true - pac-proxy-agent@7.2.0: - dependencies: - '@tootallnate/quickjs-emscripten': 0.23.0 - agent-base: 7.1.4 - debug: 4.3.4 - get-uri: 6.0.5 - http-proxy-agent: 7.0.2 - https-proxy-agent: 7.0.6 - pac-resolver: 7.0.1 - socks-proxy-agent: 8.0.5 - transitivePeerDependencies: - - supports-color - - pac-resolver@7.0.1: - dependencies: - degenerator: 5.0.1 - netmask: 2.0.2 - pako@1.0.11: {} parent-module@1.0.1: @@ -3744,21 +3622,6 @@ snapshots: retry: 0.12.0 optional: true - proxy-agent@6.5.0: - dependencies: - agent-base: 7.1.4 - debug: 4.3.4 - http-proxy-agent: 7.0.2 - https-proxy-agent: 7.0.6 - lru-cache: 7.18.3 - pac-proxy-agent: 7.2.0 - proxy-from-env: 1.1.0 - socks-proxy-agent: 8.0.5 - transitivePeerDependencies: - - supports-color - - proxy-from-env@1.1.0: {} - pump@3.0.3: dependencies: end-of-stream: 1.4.5 @@ -3877,7 +3740,8 @@ snapshots: dependencies: is-arrayish: 0.3.2 - smart-buffer@4.2.0: {} + smart-buffer@4.2.0: + optional: true socks-proxy-agent@6.2.1: dependencies: @@ -3888,24 +3752,14 @@ snapshots: - supports-color optional: true - socks-proxy-agent@8.0.5: - dependencies: - agent-base: 7.1.4 - debug: 4.3.4 - socks: 2.8.7 - transitivePeerDependencies: - - supports-color - socks@2.8.7: dependencies: ip-address: 10.0.1 smart-buffer: 4.2.0 + optional: true source-map-js@1.2.1: {} - source-map@0.6.1: - optional: true - sqlite3@5.1.7: dependencies: bindings: 1.5.0 @@ -4020,7 +3874,8 @@ snapshots: dependencies: punycode: 2.3.1 - tslib@2.8.1: {} + tslib@2.8.1: + optional: true tunnel-agent@0.6.0: dependencies: diff --git a/src/modules/music.js b/src/modules/music.js index 3daf9bd..6e247d0 100644 --- a/src/modules/music.js +++ b/src/modules/music.js @@ -3,6 +3,7 @@ const {Collection} = require("@projectdysnomia/dysnomia"); const {BG, buildURL, GOOG_API_KEY, USER_AGENT} = require("bgutils-js"); const {Innertube, YT, YTNodes} = require("youtubei.js"); const {JSDOM} = require("jsdom"); +const {ProxyAgent} = require("undici"); const ffprobe = require("node-ffprobe"); @@ -23,11 +24,27 @@ const REGEX_FILE = /^(https?:\/\/)?.*\..*\/.+\.(mp3|ogg|flac|wav|webm|mp4|mov|mk let SOUNDCLOUD_CLIENTID; +let agent; +if (hf.config.proxy) { + agent = new ProxyAgent({uri: hf.config.proxy}); +} + +async function fetchWithProxy(url, options = {}) { + if (url.toString() == "[object Request]") { + options.method = url.method; + options.headers = Object.assign(options.headers, url.headers); + url = url.url; + } + return await fetch(url, Object.assign(options, {dispatcher: agent})); +} + let yt, visitorData, integrityTokenBasedMinter; Innertube.create({ user_agent: USER_AGENT, enable_session_cache: false, player_id: "0004de42", + fetch: fetchWithProxy, + cookie: hf.config.yt_cookie, }).then(async (x) => { yt = x; visitorData = yt.session.context.client.visitorData || ""; @@ -56,7 +73,7 @@ Innertube.create({ const interpreterUrl = challengeResponse.bg_challenge.interpreter_url.private_do_not_access_or_else_trusted_resource_url_wrapped_value; - const bgScriptResponse = await fetch(`https:${interpreterUrl}`); + const bgScriptResponse = await fetch(`https:${interpreterUrl}`, {dispatcher: agent}); const interpreterJavascript = await bgScriptResponse.text(); if (interpreterJavascript) { @@ -85,6 +102,7 @@ Innertube.create({ "user-agent": USER_AGENT, }, body: JSON.stringify([requestKey, botguardResponse]), + dispatcher: agent, }); const response = await integrityTokenResponse.json(); @@ -267,7 +285,7 @@ async function enqueue({guild_id, voice_id, text_id, url, type, addedBy, suppres media, stream = false; - if (type == "yt") { + if (type === "yt" && hf.config.yt_whitelist.includes(guild_id)) { let info; let id = url; try { @@ -332,9 +350,11 @@ async function enqueue({guild_id, voice_id, text_id, url, type, addedBy, suppres quality: "best", type: "audio", });*/ - const fmt = [...videoInfo.streaming_data.formats, ...videoInfo.streaming_data.adaptive_formats].find( - (x) => x.url != null - ); + console.log(videoInfo); + const fmt = [ + ...(videoInfo.streaming_data?.formats ?? []), + ...(videoInfo.streaming_data?.adaptive_formats ?? []), + ].find((x) => x.url != null); if (fmt) { fmt.url = `${fmt.decipher(yt.session.player)}&pot=${sessionPoToken}`; media = fmt.url; @@ -345,7 +365,7 @@ async function enqueue({guild_id, voice_id, text_id, url, type, addedBy, suppres }); } } - } else if (type == "sc") { + } else if (type === "sc") { if (url?.startsWith("sc:")) url = url.replace(/^sc:/, "https://soundcloud.com/"); const client_id = await getSoundcloudClientID(); @@ -363,7 +383,7 @@ async function enqueue({guild_id, voice_id, text_id, url, type, addedBy, suppres length = info.duration; thumbnail = info.artwork_url; media = streamUrl; - } else if (type == "file") { + } else if (type === "file") { title = url; let info; @@ -453,10 +473,15 @@ async function enqueue({guild_id, voice_id, text_id, url, type, addedBy, suppres return; } + const args = ["-protocol_whitelist", "file,http,https,tcp,tls,pipe,data,crypto,httpproxy"]; + if (type == "yt" && agent) { + args.push("-http_proxy", hf.config.proxy); + } + await connection.connection.play(media, { inlineVolume: true, voiceDataTimeout: -1, - inputArgs: ["-protocol_whitelist", "file,http,https,tcp,tls,pipe,data,crypto"], + inputArgs: args, }); textChannel.createMessage({