mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
include even 0 seeders streams for series when cached in debrid
This commit is contained in:
@@ -64,8 +64,12 @@ const unrestrictQueue = new namedQueue((task, callback) => task.method()
|
||||
.then(result => callback(false, result))
|
||||
.catch((error => callback(error))), 20);
|
||||
|
||||
function hasMochConfigured(config) {
|
||||
return Object.keys(MOCHS).find(moch => config && config[moch])
|
||||
}
|
||||
|
||||
async function applyMochs(streams, config) {
|
||||
if (!streams || !streams.length || !Object.keys(MOCHS).find(moch => config[moch])) {
|
||||
if (!streams || !streams.length || !hasMochConfigured(config)) {
|
||||
return streams;
|
||||
}
|
||||
return Promise.all(Object.keys(config)
|
||||
@@ -170,23 +174,29 @@ function populateCachedLinks(streams, mochResult) {
|
||||
}
|
||||
|
||||
function populateDownloadLinks(streams, mochResults) {
|
||||
streams
|
||||
.filter(stream => stream.infoHash)
|
||||
.forEach(stream => mochResults
|
||||
.forEach(mochResult => {
|
||||
const cachedEntry = mochResult.mochStreams[stream.infoHash];
|
||||
if (!cachedEntry || !cachedEntry.cached) {
|
||||
streams.push({
|
||||
name: `[${mochResult.moch.shortName} download] ${stream.name}`,
|
||||
title: stream.title,
|
||||
url: `${RESOLVER_HOST}/${mochResult.moch.key}/${cachedEntry.url}/${streamFilename(stream)}`,
|
||||
behaviorHints: stream.behaviorHints
|
||||
})
|
||||
}
|
||||
}));
|
||||
const torrentStreams = streams.filter(stream => stream.infoHash);
|
||||
torrentStreams.forEach(stream => mochResults.forEach(mochResult => {
|
||||
const cachedEntry = mochResult.mochStreams[stream.infoHash];
|
||||
const isCached = cachedEntry && cachedEntry.cached;
|
||||
if (!isCached && isHealthyStreamForDebrid(torrentStreams, stream)) {
|
||||
streams.push({
|
||||
name: `[${mochResult.moch.shortName} download] ${stream.name}`,
|
||||
title: stream.title,
|
||||
url: `${RESOLVER_HOST}/${mochResult.moch.key}/${cachedEntry.url}/${streamFilename(stream)}`,
|
||||
behaviorHints: stream.behaviorHints
|
||||
})
|
||||
}
|
||||
}));
|
||||
return streams;
|
||||
}
|
||||
|
||||
function isHealthyStreamForDebrid(streams, stream) {
|
||||
const isZeroSeeders = /👤 0\b/.test(stream.title);
|
||||
const is4kStream = /\b4k\b/.test(stream.name);
|
||||
const isNotEnoughOptions = streams.length <= 5;
|
||||
return !isZeroSeeders || is4kStream || isNotEnoughOptions;
|
||||
}
|
||||
|
||||
function isInvalidToken(token, mochKey) {
|
||||
return token.length < MIN_API_KEY_SYMBOLS || TOKEN_BLACKLIST.includes(`${mochKey}|${token}`);
|
||||
}
|
||||
@@ -215,4 +225,4 @@ function errorStreamResponse(mochKey, error) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
module.exports = { applyMochs, getMochCatalog, getMochItemMeta, resolve, MochOptions: MOCHS }
|
||||
module.exports = { applyMochs, getMochCatalog, getMochItemMeta, resolve, hasMochConfigured, MochOptions: MOCHS }
|
||||
|
||||
Reference in New Issue
Block a user