From c306a944d953e6f8ab47f7bfe3f81f7627880fe8 Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Sun, 12 May 2024 16:12:45 +0000 Subject: [PATCH] match: add freebind support for youtube and instagram --- package.json | 3 +++ src/modules/processing/match.js | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ffb78672..1b97a04d 100644 --- a/package.json +++ b/package.json @@ -41,5 +41,8 @@ "undici": "^6.7.0", "url-pattern": "1.0.3", "youtubei.js": "^9.3.0" + }, + "optionalDependencies": { + "freebind": "^0.2.2" } } diff --git a/src/modules/processing/match.js b/src/modules/processing/match.js index a6432e49..d89dc9d9 100644 --- a/src/modules/processing/match.js +++ b/src/modules/processing/match.js @@ -25,9 +25,21 @@ import streamable from "./services/streamable.js"; import twitch from "./services/twitch.js"; import rutube from "./services/rutube.js"; import dailymotion from "./services/dailymotion.js"; +import { env } from '../config.js'; +let freebind; export default async function(host, patternMatch, url, lang, obj) { assert(url instanceof URL); + let dispatcher, requestIP; + + if (env.freebindCIDR) { + if (!freebind) { + freebind = await import('freebind'); + } + + requestIP = freebind.ip.random(env.freebindCIDR); + dispatcher = freebind.dispatcherFromIP(requestIP, { strict: false }); + } try { let r, isAudioOnly = !!obj.isAudioOnly, disableMetadata = !!obj.disableMetadata; @@ -66,7 +78,8 @@ export default async function(host, patternMatch, url, lang, obj) { format: obj.vCodec, isAudioOnly: isAudioOnly, isAudioMuted: obj.isAudioMuted, - dubLang: obj.dubLang + dubLang: obj.dubLang, + dispatcher } if (url.hostname === 'music.youtube.com' || isAudioOnly === true) { @@ -122,7 +135,8 @@ export default async function(host, patternMatch, url, lang, obj) { case "instagram": r = await instagram({ ...patternMatch, - quality: obj.vQuality + quality: obj.vQuality, + dispatcher }) break; case "vine":