From aef5fab3440a4d0b81aef5251318390e279afcfb Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Mon, 1 Feb 2021 00:25:07 +0100 Subject: [PATCH] [addon] update debrid options --- addon/moch/moch.js | 35 ++++++++++++++--------------------- addon/moch/options.js | 31 +++++++++++-------------------- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/addon/moch/moch.js b/addon/moch/moch.js index 4b1b0cf..9f2d474 100644 --- a/addon/moch/moch.js +++ b/addon/moch/moch.js @@ -45,9 +45,8 @@ async function applyMochs(streams, config) { return streams; } - const onlyCached = options.onlyCachedLinks(config); - const onlyCachedIfAvailable = options.onlyCachedLinksIfAvailable(config); - const includeDownloadLinks = options.includeDownloadLinks(config); + const includeTorrentLinks = options.includeTorrentLinks(config); + const excludeDownloadLinks = options.excludeDownloadLinks(config); const configuredMochs = Object.keys(config) .filter(configKey => MOCHS[configKey]) @@ -60,12 +59,9 @@ async function applyMochs(streams, config) { .then(results => results.filter(result => result && result.mochStreams)); const cachedStreams = mochResults .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 onlyCached || onlyCachedIfAvailable && hasCachedStreams - ? resultStreams.filter(stream => stream.url) - : resultStreams; + return includeTorrentLinks ? resultStreams : resultStreams.filter(stream => stream.url); } async function resolve(parameters) { @@ -119,19 +115,16 @@ async function getMochItemMeta(mochKey, itemId, config) { } function populateCachedLinks(streams, mochResult) { - streams - .filter(stream => stream.infoHash) - .forEach(stream => { - const cachedEntry = mochResult.mochStreams[stream.infoHash]; - if (cachedEntry && cachedEntry.cached) { - stream.name = `[${mochResult.moch.shortName}+] ${stream.name}`; - stream.url = `${RESOLVER_HOST}/${mochResult.moch.key}/${cachedEntry.url}`; - delete stream.infoHash; - delete stream.fileIndex; - delete stream.sources; - } - }); - return streams; + return streams.map(stream => { + const cachedEntry = stream.infoHash && mochResult.mochStreams[stream.infoHash]; + if (cachedEntry && cachedEntry.cached) { + return { + name: `[${mochResult.moch.shortName}+] ${stream.name}`, + url: `${RESOLVER_HOST}/${mochResult.moch.key}/${cachedEntry.url}` + }; + } + return stream; + }); } function populateDownloadLinks(streams, mochResults) { diff --git a/addon/moch/options.js b/addon/moch/options.js index 7202634..44e9df5 100644 --- a/addon/moch/options.js +++ b/addon/moch/options.js @@ -1,34 +1,25 @@ const DebridOptions = { key: 'debridoptions', options: { - onlyCached: { - key: 'onlycached', - description: 'Show only cached debrid links' + noDownloadLinks: { + key: 'nodownloadlinks', + description: 'Don\'t show download to debrid links' }, - onlyCachedIfAvailable: { - key: 'onlycachedifavailable', - description: 'Show only cached debrid links if available' - }, - downloadLinks: { - key: 'downloadlinks', - description: 'Show download to debrid links for uncached' + torrentLinks: { + key: 'torrentlinks', + description: 'Show P2P torrent links for uncached' } } } -function onlyCachedLinks(config) { +function excludeDownloadLinks(config) { 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] - .includes(DebridOptions.options.onlyCachedIfAvailable.key); + .includes(DebridOptions.options.torrentLinks.key); } -function includeDownloadLinks(config) { - return config[DebridOptions.key] && config[DebridOptions.key] - .includes(DebridOptions.options.downloadLinks.key); -} - -module.exports = { DebridOptions, onlyCachedLinks, onlyCachedLinksIfAvailable, includeDownloadLinks } \ No newline at end of file +module.exports = { DebridOptions, excludeDownloadLinks, includeTorrentLinks } \ No newline at end of file