mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] update debrid options
This commit is contained in:
@@ -45,9 +45,8 @@ async function applyMochs(streams, config) {
|
|||||||
return streams;
|
return streams;
|
||||||
}
|
}
|
||||||
|
|
||||||
const onlyCached = options.onlyCachedLinks(config);
|
const includeTorrentLinks = options.includeTorrentLinks(config);
|
||||||
const onlyCachedIfAvailable = options.onlyCachedLinksIfAvailable(config);
|
const excludeDownloadLinks = options.excludeDownloadLinks(config);
|
||||||
const includeDownloadLinks = options.includeDownloadLinks(config);
|
|
||||||
|
|
||||||
const configuredMochs = Object.keys(config)
|
const configuredMochs = Object.keys(config)
|
||||||
.filter(configKey => MOCHS[configKey])
|
.filter(configKey => MOCHS[configKey])
|
||||||
@@ -60,12 +59,9 @@ async function applyMochs(streams, config) {
|
|||||||
.then(results => results.filter(result => result && result.mochStreams));
|
.then(results => results.filter(result => result && result.mochStreams));
|
||||||
const cachedStreams = mochResults
|
const cachedStreams = mochResults
|
||||||
.reduce((resultStreams, mochResult) => populateCachedLinks(resultStreams, mochResult), streams);
|
.reduce((resultStreams, mochResult) => populateCachedLinks(resultStreams, mochResult), streams);
|
||||||
const hasCachedStreams = cachedStreams.find(stream => stream.url);
|
const resultStreams = excludeDownloadLinks ? cachedStreams : populateDownloadLinks(cachedStreams, mochResults);
|
||||||
|
|
||||||
const resultStreams = includeDownloadLinks ? populateDownloadLinks(cachedStreams, mochResults) : cachedStreams;
|
return includeTorrentLinks ? resultStreams : resultStreams.filter(stream => stream.url);
|
||||||
return onlyCached || onlyCachedIfAvailable && hasCachedStreams
|
|
||||||
? resultStreams.filter(stream => stream.url)
|
|
||||||
: resultStreams;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resolve(parameters) {
|
async function resolve(parameters) {
|
||||||
@@ -119,19 +115,16 @@ async function getMochItemMeta(mochKey, itemId, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function populateCachedLinks(streams, mochResult) {
|
function populateCachedLinks(streams, mochResult) {
|
||||||
streams
|
return streams.map(stream => {
|
||||||
.filter(stream => stream.infoHash)
|
const cachedEntry = stream.infoHash && mochResult.mochStreams[stream.infoHash];
|
||||||
.forEach(stream => {
|
if (cachedEntry && cachedEntry.cached) {
|
||||||
const cachedEntry = mochResult.mochStreams[stream.infoHash];
|
return {
|
||||||
if (cachedEntry && cachedEntry.cached) {
|
name: `[${mochResult.moch.shortName}+] ${stream.name}`,
|
||||||
stream.name = `[${mochResult.moch.shortName}+] ${stream.name}`;
|
url: `${RESOLVER_HOST}/${mochResult.moch.key}/${cachedEntry.url}`
|
||||||
stream.url = `${RESOLVER_HOST}/${mochResult.moch.key}/${cachedEntry.url}`;
|
};
|
||||||
delete stream.infoHash;
|
}
|
||||||
delete stream.fileIndex;
|
return stream;
|
||||||
delete stream.sources;
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
return streams;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateDownloadLinks(streams, mochResults) {
|
function populateDownloadLinks(streams, mochResults) {
|
||||||
|
|||||||
@@ -1,34 +1,25 @@
|
|||||||
const DebridOptions = {
|
const DebridOptions = {
|
||||||
key: 'debridoptions',
|
key: 'debridoptions',
|
||||||
options: {
|
options: {
|
||||||
onlyCached: {
|
noDownloadLinks: {
|
||||||
key: 'onlycached',
|
key: 'nodownloadlinks',
|
||||||
description: 'Show only cached debrid links'
|
description: 'Don\'t show download to debrid links'
|
||||||
},
|
},
|
||||||
onlyCachedIfAvailable: {
|
torrentLinks: {
|
||||||
key: 'onlycachedifavailable',
|
key: 'torrentlinks',
|
||||||
description: 'Show only cached debrid links if available'
|
description: 'Show P2P torrent links for uncached'
|
||||||
},
|
|
||||||
downloadLinks: {
|
|
||||||
key: 'downloadlinks',
|
|
||||||
description: 'Show download to debrid links for uncached'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onlyCachedLinks(config) {
|
function excludeDownloadLinks(config) {
|
||||||
return config[DebridOptions.key] && config[DebridOptions.key]
|
return config[DebridOptions.key] && config[DebridOptions.key]
|
||||||
.includes(DebridOptions.options.onlyCached.key);
|
.includes(DebridOptions.options.noDownloadLinks.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onlyCachedLinksIfAvailable(config) {
|
function includeTorrentLinks(config) {
|
||||||
return config[DebridOptions.key] && config[DebridOptions.key]
|
return config[DebridOptions.key] && config[DebridOptions.key]
|
||||||
.includes(DebridOptions.options.onlyCachedIfAvailable.key);
|
.includes(DebridOptions.options.torrentLinks.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function includeDownloadLinks(config) {
|
module.exports = { DebridOptions, excludeDownloadLinks, includeTorrentLinks }
|
||||||
return config[DebridOptions.key] && config[DebridOptions.key]
|
|
||||||
.includes(DebridOptions.options.downloadLinks.key);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { DebridOptions, onlyCachedLinks, onlyCachedLinksIfAvailable, includeDownloadLinks }
|
|
||||||
Reference in New Issue
Block a user