mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] use proxy when retrieving best trackers list
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
const needle = require('needle');
|
||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper');
|
||||
const { cacheWrapProxy } = require('../lib/cache');
|
||||
|
||||
const TRACKERS_URL = 'https://ngosang.github.io/trackerslist/trackers_best.txt';
|
||||
const ANIME_TRACKERS = [
|
||||
@@ -17,7 +19,12 @@ function getAllTrackers() {
|
||||
}
|
||||
|
||||
async function initBestTrackers() {
|
||||
BEST_TRACKERS = await needle('get', TRACKERS_URL, { open_timeout: 20000 })
|
||||
const userAgent = getRandomUserAgent();
|
||||
const proxy = await cacheWrapProxy('moch', () => getRandomProxy()).catch(() => getRandomProxy());
|
||||
const agent = getProxyAgent(proxy);
|
||||
const options = { timeout: 30000, agent: agent, headers: { 'User-Agent': userAgent } };
|
||||
|
||||
BEST_TRACKERS = await needle('get', TRACKERS_URL, options)
|
||||
.then(response => response.body && response.body.trim())
|
||||
.then(body => body && body.split('\n\n') || []);
|
||||
ALL_TRACKERS = BEST_TRACKERS.concat(ANIME_TRACKERS);
|
||||
|
||||
Reference in New Issue
Block a user