mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] adds debrid download link option an logic
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const options = require('./options');
|
||||
const realdebrid = require('./realdebrid');
|
||||
const premiumize = require('./premiumize');
|
||||
const alldebrid = require('./alldebrid');
|
||||
@@ -25,24 +26,34 @@ async function applyMochs(streams, config) {
|
||||
if (!streams || !streams.length) {
|
||||
return streams;
|
||||
}
|
||||
const includeDownloadLinks = options.includeDownloadLinks(config);
|
||||
|
||||
return Promise.all(Object.keys(config)
|
||||
.filter(configKey => MOCHS[configKey])
|
||||
.map(configKey => MOCHS[configKey])
|
||||
.map(moch => moch.instance.getCachedStreams(streams, config[moch.key])
|
||||
.then(cachedStreams => ({ moch, cachedStreams }))
|
||||
.then(mochStreams => ({ moch, mochStreams }))
|
||||
.catch(error => console.warn(error))))
|
||||
.then(mochResults => mochResults
|
||||
.filter(result => result && result.cachedStreams)
|
||||
.reduce((resultStreams, { moch, cachedStreams }) => {
|
||||
.filter(result => result && result.mochStreams)
|
||||
.reduce((resultStreams, { moch, mochStreams }) => {
|
||||
resultStreams
|
||||
.filter(stream => stream.infoHash)
|
||||
.filter(stream => cachedStreams[stream.infoHash])
|
||||
.filter(stream => mochStreams[stream.infoHash])
|
||||
.forEach(stream => {
|
||||
stream.name = `[${moch.shortName}+] ${stream.name}`;
|
||||
stream.url = `${RESOLVER_HOST}/${moch.key}/${cachedStreams[stream.infoHash]}`;
|
||||
delete stream.infoHash;
|
||||
delete stream.fileIndex;
|
||||
const cachedEntry = mochStreams[stream.infoHash];
|
||||
if (cachedEntry.cached) {
|
||||
stream.name = `[${moch.shortName}+] ${stream.name}`;
|
||||
stream.url = `${RESOLVER_HOST}/${moch.key}/${cachedEntry.url}`;
|
||||
delete stream.infoHash;
|
||||
delete stream.fileIndex;
|
||||
} else if (includeDownloadLinks) {
|
||||
resultStreams.push({
|
||||
name: `[${moch.shortName} download] ${stream.name}`,
|
||||
title: stream.title,
|
||||
url: `${RESOLVER_HOST}/${moch.key}/${cachedEntry.url}`
|
||||
})
|
||||
}
|
||||
});
|
||||
return resultStreams;
|
||||
}, streams));
|
||||
|
||||
Reference in New Issue
Block a user