[addon] remove agent from debrid requests
This commit is contained in:
@@ -2,8 +2,8 @@ const AllDebridClient = require('all-debrid-api');
|
|||||||
const { Type } = require('../lib/types');
|
const { Type } = require('../lib/types');
|
||||||
const { isVideo, isArchive } = require('../lib/extension');
|
const { isVideo, isArchive } = require('../lib/extension');
|
||||||
const StaticResponse = require('./static');
|
const StaticResponse = require('./static');
|
||||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper');
|
const { getRandomUserAgent } = require('../lib/requestHelper');
|
||||||
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
const { cacheUserAgent } = require('../lib/cache');
|
||||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||||
|
|
||||||
const KEY = 'alldebrid';
|
const KEY = 'alldebrid';
|
||||||
@@ -151,10 +151,8 @@ async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) {
|
|||||||
|
|
||||||
async function getDefaultOptions(id, ip) {
|
async function getDefaultOptions(id, ip) {
|
||||||
const userAgent = await cacheUserAgent(id, () => getRandomUserAgent()).catch(() => getRandomUserAgent());
|
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) {
|
function statusError(statusCode) {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ const magnet = require('magnet-uri');
|
|||||||
const { Type } = require('../lib/types');
|
const { Type } = require('../lib/types');
|
||||||
const { isVideo } = require('../lib/extension');
|
const { isVideo } = require('../lib/extension');
|
||||||
const StaticResponse = require('./static');
|
const StaticResponse = require('./static');
|
||||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper');
|
const { getRandomUserAgent } = require('../lib/requestHelper');
|
||||||
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
const { cacheUserAgent } = require('../lib/cache');
|
||||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||||
|
|
||||||
const KEY = 'premiumize';
|
const KEY = 'premiumize';
|
||||||
@@ -93,7 +93,7 @@ async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
|||||||
return cachedLink;
|
return cachedLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _resolve(PM, infoHash, cachedEntryInfo, fileIndex)
|
return _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error && error.message && error.message.includes('purchase')) {
|
if (error && error.message && error.message.includes('purchase')) {
|
||||||
console.log(`Access denied to Premiumize ${infoHash} [${fileIndex}]`);
|
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);
|
const torrent = await _createOrFindTorrent(PM, infoHash);
|
||||||
if (torrent && statusReady(torrent.status)) {
|
if (torrent && statusReady(torrent.status)) {
|
||||||
return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip);
|
return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip);
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ const { Type } = require('../lib/types');
|
|||||||
const { isVideo, isArchive } = require('../lib/extension');
|
const { isVideo, isArchive } = require('../lib/extension');
|
||||||
const delay = require('./delay');
|
const delay = require('./delay');
|
||||||
const StaticResponse = require('./static');
|
const StaticResponse = require('./static');
|
||||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent, blacklistProxy } = require('../lib/requestHelper');
|
const { getRandomUserAgent } = require('../lib/requestHelper');
|
||||||
const { cacheWrapProxy, cacheUserAgent, uncacheProxy } = require('../lib/cache');
|
const { cacheUserAgent } = require('../lib/cache');
|
||||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||||
|
|
||||||
const MIN_SIZE = 5 * 1024 * 1024; // 5 MB
|
const MIN_SIZE = 5 * 1024 * 1024; // 5 MB
|
||||||
@@ -49,8 +49,7 @@ async function _getInstantAvailable(hashes, apiKey, retries = 3) {
|
|||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (retries > 0 && BLACKLIST_ERRORS.some(v => error.message && error.message.includes(v))) {
|
if (retries > 0 && BLACKLIST_ERRORS.some(v => error.message && error.message.includes(v))) {
|
||||||
blacklistProxy(options.agent.proxy.host);
|
return _getInstantAvailable(hashes, apiKey, retries - 1);
|
||||||
return uncacheProxy('moch').then(() => _getInstantAvailable(hashes, apiKey, retries - 1));
|
|
||||||
}
|
}
|
||||||
if (retries > 0 && NON_BLACKLIST_ERRORS.some(v => error.message && error.message.includes(v))) {
|
if (retries > 0 && NON_BLACKLIST_ERRORS.some(v => error.message && error.message.includes(v))) {
|
||||||
return _getInstantAvailable(hashes, apiKey, retries - 1);
|
return _getInstantAvailable(hashes, apiKey, retries - 1);
|
||||||
@@ -74,11 +73,11 @@ function _getCachedFileIds(fileIndex, hosterResults) {
|
|||||||
return cachedTorrents.length && cachedTorrents[0] || [];
|
return cachedTorrents.length && cachedTorrents[0] || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCatalog(apiKey, offset = 0) {
|
async function getCatalog(apiKey, offset, ip) {
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const options = await getDefaultOptions(apiKey);
|
const options = await getDefaultOptions(apiKey, ip);
|
||||||
const RD = new RealDebridClient(apiKey, options);
|
const RD = new RealDebridClient(apiKey, options);
|
||||||
return _getAllTorrents(RD)
|
return _getAllTorrents(RD)
|
||||||
.then(torrents => Array.isArray(torrents) ? torrents : [])
|
.then(torrents => Array.isArray(torrents) ? torrents : [])
|
||||||
@@ -100,8 +99,8 @@ async function _getAllTorrents(RD, page = 1) {
|
|||||||
: torrents)
|
: torrents)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getItemMeta(itemId, apiKey) {
|
async function getItemMeta(itemId, apiKey, ip) {
|
||||||
const options = await getDefaultOptions(apiKey);
|
const options = await getDefaultOptions(apiKey, ip);
|
||||||
const RD = new RealDebridClient(apiKey, options);
|
const RD = new RealDebridClient(apiKey, options);
|
||||||
return _getTorrentInfo(RD, itemId)
|
return _getTorrentInfo(RD, itemId)
|
||||||
.then(torrent => ({
|
.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}]`);
|
console.log(`Unrestricting RealDebrid ${infoHash} [${fileIndex}]`);
|
||||||
const options = await getDefaultOptions(apiKey);
|
const options = await getDefaultOptions(apiKey, ip);
|
||||||
const RD = new RealDebridClient(apiKey, options);
|
const RD = new RealDebridClient(apiKey, options);
|
||||||
|
|
||||||
return _resolve(RD, infoHash, cachedEntryInfo, fileIndex)
|
return _resolve(RD, infoHash, cachedEntryInfo, fileIndex)
|
||||||
@@ -291,12 +290,10 @@ function accessDeniedError(error) {
|
|||||||
return [9, 20].includes(error && error.code);
|
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 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 };
|
module.exports = { getCachedStreams, resolve, getCatalog, getItemMeta };
|
||||||
4
addon/package-lock.json
generated
4
addon/package-lock.json
generated
@@ -2003,8 +2003,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"real-debrid-api": {
|
"real-debrid-api": {
|
||||||
"version": "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#935a5c23ae809edbcd2a111526a7f74d6767c50d",
|
"from": "git://github.com/TheBeastLT/node-real-debrid.git#874f150f4c0b6ea5c67535c82b47f75ad96e50b8",
|
||||||
"requires": {
|
"requires": {
|
||||||
"request": "^2.83.0"
|
"request": "^2.83.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
"pg": "^7.8.2",
|
"pg": "^7.8.2",
|
||||||
"pg-hstore": "^2.3.2",
|
"pg-hstore": "^2.3.2",
|
||||||
"premiumize-api": "^1.0.3",
|
"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",
|
"request-ip": "^2.1.3",
|
||||||
"sequelize": "^4.43.0",
|
"sequelize": "^4.43.0",
|
||||||
"stremio-addon-sdk": "^1.6.1",
|
"stremio-addon-sdk": "^1.6.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user