[addon] add bingeGroup to stream responses

This commit is contained in:
TheBeastLT
2021-02-05 09:37:36 +01:00
parent 6c95f0e22c
commit 154b639a11
6 changed files with 24 additions and 11 deletions

View File

@@ -45,7 +45,7 @@ async function getBestTrackers(retry = 2) {
.catch(error => {
if (retry === 0) {
console.log(`Failed retrieving best trackers: ${error.message}`);
return [];
throw error;
}
return getBestTrackers(retry - 1);
});

View File

@@ -15,7 +15,10 @@ const ANIME_PROVIDERS = [
function toStreamInfo(record) {
const torrentInfo = titleParser.parse(record.torrent.title);
const fileInfo = titleParser.parse(record.title);
const sameInfo = !Number.isInteger(record.fileIndex) || Math.abs(record.size / record.torrent.size - 1) < SIZE_DELTA;
const sameInfo = !Number.isInteger(record.fileIndex)
|| Math.abs(record.size / record.torrent.size - 1) < SIZE_DELTA
|| record.title.includes(record.torrent.title);
const quality = getQuality(record, torrentInfo, fileInfo);
const title = joinDetailParts(
[
joinDetailParts([record.torrent.title.replace(/[, ]+/g, ' ')]),
@@ -33,17 +36,23 @@ function toStreamInfo(record) {
const name = joinDetailParts(
[
joinDetailParts([ADDON_NAME]),
joinDetailParts([getQuality(record, torrentInfo, fileInfo)])
joinDetailParts([quality])
],
'',
'\n'
);
const behaviorHints = {
bingeGroup: sameInfo
? `torrentio|${quality}|${fileInfo.group}`
: `torrentio|${record.infoHash}`
};
return {
name: name,
title: title,
infoHash: record.infoHash,
fileIdx: record.fileIndex
fileIdx: record.fileIndex,
behaviorHints: record.torrent.type !== Type.MOVIE ? behaviorHints : null
};
}
@@ -96,7 +105,7 @@ function applyStaticInfo(streams) {
return streams.map(stream => enrichStaticInfo(stream));
}
function enrichStaticInfo(stream) {
function enrichStreamSources(stream) {
const match = stream.title.match(/⚙.* ([^ \n]+)/);
const provider = match && match[1].toLowerCase();
if (ANIME_PROVIDERS.includes(provider)) {
@@ -107,4 +116,8 @@ function enrichStaticInfo(stream) {
return stream;
}
function enrichStaticInfo(stream) {
return enrichStreamSources(stream);
}
module.exports = { toStreamInfo, applyStaticInfo };