improve sources for russian providers

This commit is contained in:
TheBeastLT
2023-01-05 14:05:34 +02:00
parent 84507951e6
commit d5d528baa0
2 changed files with 47 additions and 30 deletions

View File

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

View File

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