From 473747bd33f788a0dbe1b6d77494eb89fa73a8ec Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Mon, 1 Feb 2021 19:11:29 +0100 Subject: [PATCH] [addon] remove agent from debrid requests --- addon/moch/alldebrid.js | 8 +++----- addon/moch/premiumize.js | 8 ++++---- addon/moch/realdebrid.js | 25 +++++++++++-------------- addon/package-lock.json | 4 ++-- addon/package.json | 2 +- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/addon/moch/alldebrid.js b/addon/moch/alldebrid.js index c7441c4..c564b16 100644 --- a/addon/moch/alldebrid.js +++ b/addon/moch/alldebrid.js @@ -2,8 +2,8 @@ const AllDebridClient = require('all-debrid-api'); const { Type } = require('../lib/types'); const { isVideo, isArchive } = require('../lib/extension'); const StaticResponse = require('./static'); -const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper'); -const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache'); +const { getRandomUserAgent } = require('../lib/requestHelper'); +const { cacheUserAgent } = require('../lib/cache'); const { getMagnetLink } = require('../lib/magnetHelper'); const KEY = 'alldebrid'; @@ -151,10 +151,8 @@ async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) { async function getDefaultOptions(id, ip) { const userAgent = await cacheUserAgent(id, () => getRandomUserAgent()).catch(() => getRandomUserAgent()); - const proxy = await cacheWrapProxy('moch', () => getRandomProxy()).catch(() => getRandomProxy()); - const agent = getProxyAgent(proxy); - return { base_agent: AGENT, timeout: 30000, agent: agent, headers: { 'User-Agent': userAgent } }; + return { base_agent: AGENT, timeout: 30000, headers: { 'User-Agent': userAgent } }; } function statusError(statusCode) { diff --git a/addon/moch/premiumize.js b/addon/moch/premiumize.js index 8bcc2e2..c8bd9f0 100644 --- a/addon/moch/premiumize.js +++ b/addon/moch/premiumize.js @@ -3,8 +3,8 @@ const magnet = require('magnet-uri'); const { Type } = require('../lib/types'); const { isVideo } = require('../lib/extension'); const StaticResponse = require('./static'); -const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper'); -const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache'); +const { getRandomUserAgent } = require('../lib/requestHelper'); +const { cacheUserAgent } = require('../lib/cache'); const { getMagnetLink } = require('../lib/magnetHelper'); const KEY = 'premiumize'; @@ -93,7 +93,7 @@ async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) { return cachedLink; } - return _resolve(PM, infoHash, cachedEntryInfo, fileIndex) + return _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip) .catch(error => { if (error && error.message && error.message.includes('purchase')) { console.log(`Access denied to Premiumize ${infoHash} [${fileIndex}]`); @@ -103,7 +103,7 @@ async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) { }); } -async function _resolve(PM, infoHash, cachedEntryInfo, fileIndex) { +async function _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip) { const torrent = await _createOrFindTorrent(PM, infoHash); if (torrent && statusReady(torrent.status)) { return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip); diff --git a/addon/moch/realdebrid.js b/addon/moch/realdebrid.js index cb08d73..8eaf2d3 100644 --- a/addon/moch/realdebrid.js +++ b/addon/moch/realdebrid.js @@ -3,8 +3,8 @@ const { Type } = require('../lib/types'); const { isVideo, isArchive } = require('../lib/extension'); const delay = require('./delay'); const StaticResponse = require('./static'); -const { getRandomProxy, getProxyAgent, getRandomUserAgent, blacklistProxy } = require('../lib/requestHelper'); -const { cacheWrapProxy, cacheUserAgent, uncacheProxy } = require('../lib/cache'); +const { getRandomUserAgent } = require('../lib/requestHelper'); +const { cacheUserAgent } = require('../lib/cache'); const { getMagnetLink } = require('../lib/magnetHelper'); const MIN_SIZE = 5 * 1024 * 1024; // 5 MB @@ -49,8 +49,7 @@ async function _getInstantAvailable(hashes, apiKey, retries = 3) { }) .catch(error => { if (retries > 0 && BLACKLIST_ERRORS.some(v => error.message && error.message.includes(v))) { - blacklistProxy(options.agent.proxy.host); - return uncacheProxy('moch').then(() => _getInstantAvailable(hashes, apiKey, retries - 1)); + return _getInstantAvailable(hashes, apiKey, retries - 1); } if (retries > 0 && NON_BLACKLIST_ERRORS.some(v => error.message && error.message.includes(v))) { return _getInstantAvailable(hashes, apiKey, retries - 1); @@ -74,11 +73,11 @@ function _getCachedFileIds(fileIndex, hosterResults) { return cachedTorrents.length && cachedTorrents[0] || []; } -async function getCatalog(apiKey, offset = 0) { +async function getCatalog(apiKey, offset, ip) { if (offset > 0) { return []; } - const options = await getDefaultOptions(apiKey); + const options = await getDefaultOptions(apiKey, ip); const RD = new RealDebridClient(apiKey, options); return _getAllTorrents(RD) .then(torrents => Array.isArray(torrents) ? torrents : []) @@ -100,8 +99,8 @@ async function _getAllTorrents(RD, page = 1) { : torrents) } -async function getItemMeta(itemId, apiKey) { - const options = await getDefaultOptions(apiKey); +async function getItemMeta(itemId, apiKey, ip) { + const options = await getDefaultOptions(apiKey, ip); const RD = new RealDebridClient(apiKey, options); return _getTorrentInfo(RD, itemId) .then(torrent => ({ @@ -122,9 +121,9 @@ async function getItemMeta(itemId, apiKey) { })) } -async function resolve({ apiKey, infoHash, cachedEntryInfo, fileIndex }) { +async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) { console.log(`Unrestricting RealDebrid ${infoHash} [${fileIndex}]`); - const options = await getDefaultOptions(apiKey); + const options = await getDefaultOptions(apiKey, ip); const RD = new RealDebridClient(apiKey, options); return _resolve(RD, infoHash, cachedEntryInfo, fileIndex) @@ -291,12 +290,10 @@ function accessDeniedError(error) { return [9, 20].includes(error && error.code); } -async function getDefaultOptions(id) { +async function getDefaultOptions(id, ip) { 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 { ip, 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 18fd313..db010f9 100644 --- a/addon/package-lock.json +++ b/addon/package-lock.json @@ -2003,8 +2003,8 @@ } }, "real-debrid-api": { - "version": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d", - "from": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d", + "version": "git://github.com/TheBeastLT/node-real-debrid.git#874f150f4c0b6ea5c67535c82b47f75ad96e50b8", + "from": "git://github.com/TheBeastLT/node-real-debrid.git#874f150f4c0b6ea5c67535c82b47f75ad96e50b8", "requires": { "request": "^2.83.0" } diff --git a/addon/package.json b/addon/package.json index 87ad6a9..8a694de 100644 --- a/addon/package.json +++ b/addon/package.json @@ -22,7 +22,7 @@ "pg": "^7.8.2", "pg-hstore": "^2.3.2", "premiumize-api": "^1.0.3", - "real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d", + "real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#874f150f4c0b6ea5c67535c82b47f75ad96e50b8", "request-ip": "^2.1.3", "sequelize": "^4.43.0", "stremio-addon-sdk": "^1.6.1",