From d5d528baa021fdb69077a29069dab7f1ca7a5db1 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Thu, 5 Jan 2023 14:05:34 +0200 Subject: [PATCH] improve sources for russian providers --- addon/lib/magnetHelper.js | 52 ++++++++++++++++++++++++++++++++++----- addon/lib/streamInfo.js | 25 +------------------ 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/addon/lib/magnetHelper.js b/addon/lib/magnetHelper.js index ee40dc2..396c5c4 100644 --- a/addon/lib/magnetHelper.js +++ b/addon/lib/magnetHelper.js @@ -13,6 +13,14 @@ const ANIME_TRACKERS = [ "http://share.camoe.cn:8080/announce", "http://t.nyaatracker.com:80/announce" ]; +const RUSSIAN_TRACKERS = [ + "udp://opentor.org:2710", + "http://retracker.local/announce", + "http://bt.t-ru.org/ann?magnet", + "http://bt2.t-ru.org/ann?magnet", + "http://bt3.t-ru.org/ann?magnet", + "http://bt4.t-ru.org/ann?magnet" +] // Some trackers have limits on original torrent trackers, // where downloading ip has to seed the torrents for some amount of time, // thus it doesn't work on mochs. @@ -21,19 +29,25 @@ const ANIME_TRACKERS = [ const LIMITED_PROVIDERS = [ 'Rutor' ]; +const ANIME_PROVIDERS = [ + 'HorribleSubs', + 'NyaaSi', + 'NyaaPantsu' +]; +const RUSSIAN_PROVIDERS = [ + 'Rutor', + 'Rutracker' +] let BEST_TRACKERS = []; let ALL_TRACKERS = []; -function getAllTrackers() { - return ALL_TRACKERS; -} - async function getMagnetLink(infoHash) { const torrent = await getTorrent(infoHash).catch(() => ({ infoHash })); const torrentTrackers = !LIMITED_PROVIDERS.includes(torrent.provider) && torrent.trackers && torrent.trackers.split(','); const animeTrackers = torrent.type === Type.ANIME ? ALL_TRACKERS : undefined; - const trackers = torrentTrackers || animeTrackers; + const providerTrackers = RUSSIAN_PROVIDERS.includes(torrent.provider) && RUSSIAN_TRACKERS; + const trackers = unique([].concat(torrentTrackers).concat(animeTrackers).concat(providerTrackers)); return trackers ? magnet.encode({ infoHash: infoHash, announce: trackers }) @@ -60,4 +74,30 @@ async function getBestTrackers(retry = 2) { }); } -module.exports = { initBestTrackers, getAllTrackers, getMagnetLink }; \ No newline at end of file +function getSources(trackersInput, infoHash) { + if (!trackersInput) { + return null; + } + const trackers = Array.isArray(trackersInput) ? trackersInput : trackersInput.split(','); + return trackers.map(tracker => `tracker:${tracker}`).concat(`dht:${infoHash}`); +} + +function enrichStreamSources(stream) { + const match = stream.title.match(/⚙.* ([^ \n]+)/); + const provider = match && match[1]; + if (ANIME_PROVIDERS.includes(provider)) { + const sources = getSources(ALL_TRACKERS, stream.infoHash); + return { ...stream, sources }; + } + if (RUSSIAN_PROVIDERS.includes(provider)) { + const sources = unique([].concat(stream.sources).concat(getSources(RUSSIAN_TRACKERS, stream.infoHash))); + return { ...stream, sources }; + } + return stream; +} + +function unique(array) { + return Array.from(new Set(array)); +} + +module.exports = { initBestTrackers, getMagnetLink, getSources, enrichStreamSources }; \ No newline at end of file diff --git a/addon/lib/streamInfo.js b/addon/lib/streamInfo.js index 1fb54e8..f067f08 100644 --- a/addon/lib/streamInfo.js +++ b/addon/lib/streamInfo.js @@ -1,17 +1,12 @@ const titleParser = require('parse-torrent-title'); const { Type } = require('./types'); const { mapLanguages } = require('./languages'); -const { getAllTrackers } = require('./magnetHelper'); +const { enrichStreamSources, getSources } = require('./magnetHelper'); const ADDON_NAME = 'Torrentio'; const SIZE_DELTA = 0.02; const UNKNOWN_SIZE = 300000000; const CAM_SOURCES = ['CAM', 'TeleSync', 'TeleCine', 'SCR']; -const ANIME_PROVIDERS = [ - 'HorribleSubs', - 'NyaaSi', - 'NyaaPantsu' -].map(provider => provider.toLowerCase()); function toStreamInfo(record) { const torrentInfo = titleParser.parse(record.torrent.title); @@ -114,28 +109,10 @@ function applyStaticInfo(streams) { return streams.map(stream => enrichStaticInfo(stream)); } -function enrichStreamSources(stream) { - const match = stream.title.match(/⚙.* ([^ \n]+)/); - const provider = match && match[1].toLowerCase(); - if (ANIME_PROVIDERS.includes(provider)) { - const sources = getSources(getAllTrackers(), stream.infoHash); - return { ...stream, sources }; - } - return stream; -} - function enrichStaticInfo(stream) { return enrichStreamSources(stream); } -function getSources(trackersInput, infoHash) { - if (!trackersInput) { - return null; - } - const trackers = Array.isArray(trackersInput) ? trackersInput : trackersInput.split(','); - return trackers.map(tracker => `tracker:${tracker}`).concat(`dht:${infoHash}`); -} - function getBingeGroupParts(record, sameInfo, quality, torrentInfo, fileInfo) { if (record.torrent.type === Type.MOVIE) { const source = torrentInfo.source || fileInfo.source