mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] updates to use https proxy agent
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const UserAgent = require('user-agents');
|
||||
const HttpsProxyAgent = require('https-proxy-agent');
|
||||
|
||||
const PROXY_HOSTS = process.env.PROXY_HOSTS && process.env.PROXY_HOSTS.split(',');
|
||||
const PROXY_PORT = 89;
|
||||
const PROXY_USERNAME = process.env.PROXY_USERNAME;
|
||||
const PROXY_PASSWORD = process.env.PROXY_PASSWORD;
|
||||
const userAgent = new UserAgent();
|
||||
@@ -13,12 +15,16 @@ function getRandomProxy() {
|
||||
if (PROXY_HOSTS && PROXY_HOSTS.length && PROXY_USERNAME && PROXY_PASSWORD) {
|
||||
const proxyHost = PROXY_HOSTS[Math.floor(Math.random() * PROXY_HOSTS.length)];
|
||||
console.log(`Using ${proxyHost} proxy`);
|
||||
return `http://${PROXY_USERNAME}:${PROXY_PASSWORD}@${proxyHost}`;
|
||||
return `https://${PROXY_USERNAME}:${PROXY_PASSWORD}@${proxyHost}:${PROXY_PORT}`;
|
||||
}
|
||||
console.warn('No proxy configured!');
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getProxyAgent(proxy) {
|
||||
return new HttpsProxyAgent(proxy);
|
||||
}
|
||||
|
||||
function blacklistProxy(proxy) {
|
||||
const proxyHost = proxy.replace(/.*@/, '');
|
||||
console.warn(`Blacklisting ${proxyHost}`);
|
||||
@@ -27,4 +33,4 @@ function blacklistProxy(proxy) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getRandomUserAgent, getRandomProxy, blacklistProxy };
|
||||
module.exports = { getRandomUserAgent, getRandomProxy, getProxyAgent, blacklistProxy };
|
||||
@@ -1,7 +1,7 @@
|
||||
const AllDebridClient = require('all-debrid-api');
|
||||
const { isVideo, isArchive } = require('../lib/extension');
|
||||
const StaticResponse = require('./static');
|
||||
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
|
||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper');
|
||||
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
||||
|
||||
async function getCachedStreams(streams, apiKey) {
|
||||
@@ -101,8 +101,9 @@ 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 { proxy: proxy, headers: { 'User-Agent': userAgent } };
|
||||
return { timeout: 30000, agent: agent, headers: { 'User-Agent': userAgent } };
|
||||
}
|
||||
|
||||
function statusError(statusCode) {
|
||||
|
||||
@@ -2,7 +2,7 @@ const PremiumizeClient = require('premiumize-api');
|
||||
const { encode } = require('magnet-uri');
|
||||
const { isVideo } = require('../lib/extension');
|
||||
const StaticResponse = require('./static');
|
||||
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
|
||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper');
|
||||
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
||||
|
||||
async function getCachedStreams(streams, apiKey) {
|
||||
@@ -107,8 +107,9 @@ function statusReady(status) {
|
||||
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 { proxy: proxy, headers: { 'User-Agent': userAgent } };
|
||||
return { timeout: 30000, agent: agent, headers: { 'User-Agent': userAgent } };
|
||||
}
|
||||
|
||||
module.exports = { getCachedStreams, resolve };
|
||||
@@ -3,7 +3,7 @@ const { encode } = require('magnet-uri');
|
||||
const { isVideo, isArchive } = require('../lib/extension');
|
||||
const delay = require('./delay');
|
||||
const StaticResponse = require('./static');
|
||||
const { getRandomProxy, getRandomUserAgent, blacklistProxy } = require('../lib/request_helper');
|
||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent, blacklistProxy } = require('../lib/requestHelper');
|
||||
const { cacheWrapProxy, cacheUserAgent, uncacheProxy } = require('../lib/cache');
|
||||
|
||||
const MIN_SIZE = 15728640; // 15 MB
|
||||
@@ -204,8 +204,9 @@ function statusReady(status) {
|
||||
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, proxy: proxy, headers: { 'User-Agent': userAgent } };
|
||||
return { timeout: 30000, agent: agent, headers: { 'User-Agent': userAgent } };
|
||||
}
|
||||
|
||||
module.exports = { getCachedStreams, resolve };
|
||||
47
addon/package-lock.json
generated
47
addon/package-lock.json
generated
@@ -78,6 +78,29 @@
|
||||
"integrity": "sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ==",
|
||||
"dev": true
|
||||
},
|
||||
"agent-base": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.1.tgz",
|
||||
"integrity": "sha512-01q25QQDwLSsyfhrKbn8yuur+JNw0H+0Y4JiGIKd3z9aYk/w/2kxD/Upc+t2ZBBSUNff50VjPsSW2YxM8QYKVg==",
|
||||
"requires": {
|
||||
"debug": "4"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"ajv": {
|
||||
"version": "6.12.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.0.tgz",
|
||||
@@ -1256,6 +1279,30 @@
|
||||
"sshpk": "^1.7.0"
|
||||
}
|
||||
},
|
||||
"https-proxy-agent": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
|
||||
"integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==",
|
||||
"requires": {
|
||||
"agent-base": "6",
|
||||
"debug": "4"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"cache-manager": "^2.11.1",
|
||||
"cache-manager-mongodb": "^0.2.2",
|
||||
"express-rate-limit": "^5.1.1",
|
||||
"https-proxy-agent": "^5.0.0",
|
||||
"magnet-uri": "^5.1.7",
|
||||
"named-queue": "^2.2.1",
|
||||
"needle": "^2.2.4",
|
||||
|
||||
Reference in New Issue
Block a user