From 58695b8dae5cce4b12b4b46c83973e53e675ef97 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Thu, 24 Dec 2020 12:18:18 +0100 Subject: [PATCH] [addon] use proxy when retrieving best trackers list --- addon/lib/magnetHelper.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addon/lib/magnetHelper.js b/addon/lib/magnetHelper.js index de1e343..08868d1 100644 --- a/addon/lib/magnetHelper.js +++ b/addon/lib/magnetHelper.js @@ -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);