[addon] adds debrid download link option an logic

This commit is contained in:
TheBeastLT
2020-05-10 21:33:53 +02:00
parent 3662eda2bc
commit 0c8c813756
5 changed files with 82 additions and 35 deletions

View File

@@ -17,18 +17,18 @@ async function getCachedStreams(streams, apiKey) {
console.warn('Failed AllDebrid cached torrent availability request: ', error);
return undefined;
});
return available && available.data && available.data.magnets
.filter(magnet => magnet.instant)
.reduce((cachedStreams, magnet) => {
const stream = streams.find(stream => stream.infoHash === magnet.hash.toLowerCase());
if (stream) {
const streamTitleParts = stream.title.replace(/\n👤.*/s, '').split('\n');
const fileName = streamTitleParts[streamTitleParts.length - 1];
const fileIndex = streamTitleParts.length === 2 ? stream.fileIdx : null;
const encodedFileName = encodeURIComponent(fileName);
cachedStreams[stream.infoHash] = `${apiKey}/${stream.infoHash}/${encodedFileName}/${fileIndex}`;
return available && available.data && streams
.reduce((mochStreams, stream) => {
const cachedEntry = available.data.magnets.find(magnet => stream.infoHash === magnet.hash.toLowerCase());
const streamTitleParts = stream.title.replace(/\n👤.*/s, '').split('\n');
const fileName = streamTitleParts[streamTitleParts.length - 1];
const fileIndex = streamTitleParts.length === 2 ? stream.fileIdx : null;
const encodedFileName = encodeURIComponent(fileName);
mochStreams[stream.infoHash] = {
url: `${apiKey}/${stream.infoHash}/${encodedFileName}/${fileIndex}`,
cached: cachedEntry && cachedEntry.instant
}
return cachedStreams;
return mochStreams;
}, {})
}