[addon] return torrent trackers if available

This commit is contained in:
TheBeastLT
2021-02-15 13:53:51 +01:00
parent e20ed50f17
commit 9a8612e2e6

View File

@@ -47,13 +47,14 @@ function toStreamInfo(record) {
: `torrentio|${record.infoHash}` : `torrentio|${record.infoHash}`
}; };
return { return cleanOutputObject({
name: name, name: name,
title: title, title: title,
infoHash: record.infoHash, infoHash: record.infoHash,
fileIdx: record.fileIndex, fileIdx: record.fileIndex,
behaviorHints: record.torrent.type !== Type.MOVIE ? behaviorHints : null behaviorHints: record.torrent.type !== Type.MOVIE ? behaviorHints : null,
}; sources: getSources(record.torrent.trackers, record.infoHash)
});
} }
function getQuality(record, torrentInfo, fileInfo) { function getQuality(record, torrentInfo, fileInfo) {
@@ -109,8 +110,7 @@ function enrichStreamSources(stream) {
const match = stream.title.match(/⚙.* ([^ \n]+)/); const match = stream.title.match(/⚙.* ([^ \n]+)/);
const provider = match && match[1].toLowerCase(); const provider = match && match[1].toLowerCase();
if (ANIME_PROVIDERS.includes(provider)) { if (ANIME_PROVIDERS.includes(provider)) {
const infoHash = stream.infoHash; const sources = getSources(getAllTrackers(), stream.infoHash);
const sources = getAllTrackers().map(tracker => `tracker:${tracker}`).concat(`dht:${infoHash}`);
return { ...stream, sources }; return { ...stream, sources };
} }
return stream; return stream;
@@ -120,4 +120,16 @@ function enrichStaticInfo(stream) {
return enrichStreamSources(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 cleanOutputObject(object) {
return Object.fromEntries(Object.entries(object).filter(([_, v]) => v != null));
}
module.exports = { toStreamInfo, applyStaticInfo }; module.exports = { toStreamInfo, applyStaticInfo };