[addon] use proxy when retrieving best trackers list

This commit is contained in:
TheBeastLT
2020-12-24 12:18:18 +01:00
parent d299f4e024
commit 58695b8dae

View File

@@ -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);