From 0a68bec37aec0c6e813bb1f304c8ba0809a476bc Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Sun, 31 Jan 2021 22:55:37 +0100 Subject: [PATCH] [addon] propagate ip to debrid catalog/meta requests --- addon/moch/moch.js | 4 ++-- addon/moch/premiumize.js | 12 +++++------- addon/package-lock.json | 6 +++--- addon/package.json | 2 +- addon/serverless.js | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/addon/moch/moch.js b/addon/moch/moch.js index b2d6fe1..4b1b0cf 100644 --- a/addon/moch/moch.js +++ b/addon/moch/moch.js @@ -98,7 +98,7 @@ async function getMochCatalog(mochKey, config) { return Promise.reject(`Invalid API key for moch provider: ${mochKey}`); } - return moch.instance.getCatalog(config[moch.key], config.skip); + return moch.instance.getCatalog(config[moch.key], config.skip, config.ip); } async function getMochItemMeta(mochKey, itemId, config) { @@ -107,7 +107,7 @@ async function getMochItemMeta(mochKey, itemId, config) { return Promise.reject(`Not a valid moch provider: ${mochKey}`); } - return moch.instance.getItemMeta(itemId, config[moch.key]) + return moch.instance.getItemMeta(itemId, config[moch.key], config.ip) .then(meta => { meta.videos .map(video => video.streams) diff --git a/addon/moch/premiumize.js b/addon/moch/premiumize.js index 612fa96..d6c63e8 100644 --- a/addon/moch/premiumize.js +++ b/addon/moch/premiumize.js @@ -49,11 +49,11 @@ async function getCatalog(apiKey, offset = 0) { }))); } -async function getItemMeta(itemId, apiKey) { +async function getItemMeta(itemId, apiKey, ip) { const options = await getDefaultOptions(apiKey); const PM = new PremiumizeClient(apiKey, options); const rootFolder = await PM.folder.list(itemId, null); - return getFolderContents(PM, itemId) + return getFolderContents(PM, itemId, ip) .then(contents => ({ id: `${KEY}:${itemId}`, type: Type.OTHER, @@ -85,7 +85,7 @@ async function getFolderContents(PM, itemId, ip, folderPrefix = '') { async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) { console.log(`Unrestricting ${infoHash} [${fileIndex}] for IP ${ip}`); - const options = await getDefaultOptions(apiKey, ip); + const options = await getDefaultOptions(apiKey); const PM = new PremiumizeClient(apiKey, options); const cachedLink = await _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip).catch(() => undefined); @@ -160,12 +160,10 @@ function statusReady(status) { return ['finished', 'seeding'].includes(status); } -async function getDefaultOptions(id, ip) { +async function getDefaultOptions(id) { const userAgent = await cacheUserAgent(id, () => getRandomUserAgent()).catch(() => getRandomUserAgent()); - const proxy = await cacheWrapProxy('moch', () => getRandomProxy()).catch(() => getRandomProxy()); - const agent = getProxyAgent(proxy); - return { timeout: 30000, agent: agent, headers: { 'User-Agent': userAgent } }; + return { timeout: 30000, headers: { 'User-Agent': userAgent } }; } module.exports = { getCachedStreams, resolve, getCatalog, getItemMeta }; \ No newline at end of file diff --git a/addon/package-lock.json b/addon/package-lock.json index 6a84d2d..c1a063a 100644 --- a/addon/package-lock.json +++ b/addon/package-lock.json @@ -1918,9 +1918,9 @@ "dev": true }, "premiumize-api": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/premiumize-api/-/premiumize-api-1.0.2.tgz", - "integrity": "sha512-lp5AJ+0dP3wWH/UhciNvUW6OVXKJAj3uNXjN5TWlKIS62aEynlPaYWms7DnacwwZ1cFfJXY8RblBsUUja6p97w==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/premiumize-api/-/premiumize-api-1.0.3.tgz", + "integrity": "sha512-WwJhgmwrKrFFtfjU2EMAaYv602xbe52oaGEwVJXO3z0LZQZ8Cogk9MBADcT0hrFf8MuI7zn5cPMxcJRJPr9cMQ==", "requires": { "request": "^2.83.0" } diff --git a/addon/package.json b/addon/package.json index 5b33129..54e9469 100644 --- a/addon/package.json +++ b/addon/package.json @@ -21,7 +21,7 @@ "parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#3e3932737604f4a9215a6800f6c263bb2f92f1ce", "pg": "^7.8.2", "pg-hstore": "^2.3.2", - "premiumize-api": "^1.0.2", + "premiumize-api": "^1.0.3", "real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d", "request-ip": "^2.1.3", "sequelize": "^4.43.0", diff --git a/addon/serverless.js b/addon/serverless.js index b29b79f..ada9257 100644 --- a/addon/serverless.js +++ b/addon/serverless.js @@ -39,7 +39,7 @@ router.get('/:configuration?/manifest.json', (req, res) => { router.get('/:configuration/:resource/:type/:id/:extra?.json', (req, res, next) => { const { configuration, resource, type, id } = req.params; const extra = req.params.extra ? qs.parse(req.url.split('/').pop().slice(0, -5)) : {} - const configValues = { ...extra, ...parseConfiguration(configuration) }; + const configValues = { ...extra, ...parseConfiguration(configuration), ip: requestIp.getClientIp(req) }; addonInterface.get(resource, type, id, configValues) .then(resp => { const cacheHeaders = {