mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] retry getting best trackers during startup
This commit is contained in:
@@ -32,17 +32,23 @@ async function getMagnetLink(infoHash) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function initBestTrackers() {
|
async function initBestTrackers() {
|
||||||
const options = { timeout: 30000, headers: { 'User-Agent': getRandomUserAgent() } };
|
BEST_TRACKERS = await getBestTrackers();
|
||||||
|
|
||||||
BEST_TRACKERS = await needle('get', TRACKERS_URL, options)
|
|
||||||
.then(response => response.body && response.body.trim())
|
|
||||||
.then(body => body && body.split('\n\n') || [])
|
|
||||||
.catch(error => {
|
|
||||||
console.log(`Failed retrieving best trackers: ${error.message}`);
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
ALL_TRACKERS = BEST_TRACKERS.concat(ANIME_TRACKERS);
|
ALL_TRACKERS = BEST_TRACKERS.concat(ANIME_TRACKERS);
|
||||||
console.log('Retrieved best trackers: ', BEST_TRACKERS);
|
console.log('Retrieved best trackers: ', BEST_TRACKERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getBestTrackers(retry = 2) {
|
||||||
|
const options = { timeout: 30000, headers: { 'User-Agent': getRandomUserAgent() } };
|
||||||
|
return needle('get', TRACKERS_URL, options)
|
||||||
|
.then(response => response.body && response.body.trim())
|
||||||
|
.then(body => body && body.split('\n\n') || [])
|
||||||
|
.catch(error => {
|
||||||
|
if (retry === 0) {
|
||||||
|
console.log(`Failed retrieving best trackers: ${error.message}`);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return getBestTrackers(retry - 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = { initBestTrackers, getAllTrackers, getMagnetLink };
|
module.exports = { initBestTrackers, getAllTrackers, getMagnetLink };
|
||||||
@@ -84,7 +84,7 @@ async function getFolderContents(PM, itemId, ip, folderPrefix = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
||||||
console.log(`Unrestricting ${infoHash} [${fileIndex}] for IP ${ip}`);
|
console.log(`Unrestricting Premiumize ${infoHash} [${fileIndex}] for IP ${ip}`);
|
||||||
const options = await getDefaultOptions(apiKey);
|
const options = await getDefaultOptions(apiKey);
|
||||||
const PM = new PremiumizeClient(apiKey, options);
|
const PM = new PremiumizeClient(apiKey, options);
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ async function _getCachedLink(PM, infoHash, encodedFileName, fileIndex, ip) {
|
|||||||
? videos.find(video => video.path.includes(targetFileName))
|
? videos.find(video => video.path.includes(targetFileName))
|
||||||
: videos.sort((a, b) => b.size - a.size)[0];
|
: videos.sort((a, b) => b.size - a.size)[0];
|
||||||
const unrestrictedLink = targetVideo.stream_link || targetVideo.link;
|
const unrestrictedLink = targetVideo.stream_link || targetVideo.link;
|
||||||
console.log(`Unrestricted ${infoHash} [${fileIndex}] to ${unrestrictedLink}`);
|
console.log(`Unrestricted Premiumize ${infoHash} [${fileIndex}] to ${unrestrictedLink}`);
|
||||||
return unrestrictedLink;
|
return unrestrictedLink;
|
||||||
}
|
}
|
||||||
return Promise.reject('No cached entry found');
|
return Promise.reject('No cached entry found');
|
||||||
|
|||||||
Reference in New Issue
Block a user