[addon] fix multiple entries from same torrent issue

This commit is contained in:
TheBeastLT
2020-03-17 22:57:31 +01:00
parent 60b74683d4
commit 1308b9eb7a

View File

@@ -11,23 +11,18 @@ const PROXY_PASSWORD = process.env.PROXY_PASSWORD;
async function applyMoch(streams, apiKey) { async function applyMoch(streams, apiKey) {
const RD = new RealDebridClient(apiKey); const RD = new RealDebridClient(apiKey);
const hashes = streams.map(stream => stream.infoHash); const hashes = streams.map(stream => stream.infoHash);
const streamMapping = streams.reduce((map, stream) => (map[stream.infoHash] = stream, map), {});
const available = await _instantAvailability(RD, hashes); const available = await _instantAvailability(RD, hashes);
if (available) { if (available) {
Object.entries(available) streams.forEach(stream => {
.map(([key, value]) => ({ const cachedEntry = available[stream.infoHash];
cachedInfoHash: key.toLowerCase(), const cachedIds = getCachedFileIds(stream.fileIdx, cachedEntry);
cachedFileIds: getCachedFileIds(streamMapping[key.toLowerCase()].fileIdx, value) if (cachedIds && cachedIds.length) {
})) stream.name = `[RD Cached]\n${stream.name}`;
.filter(cachedEntry => cachedEntry.cachedFileIds && cachedEntry.cachedFileIds.length) stream.url = `${ADDON_HOST}/realdebrid/${apiKey}/${stream.infoHash}/${cachedIds.join(',')}/${stream.fileIdx}`;
.forEach(cachedEntry => { delete stream.infoHash;
const stream = streamMapping[cachedEntry.cachedInfoHash]; delete stream.fileIndex;
const cachedIds = cachedEntry.cachedFileIds.join(','); }
stream.name = `[RD Cached]\n${stream.name}`; });
stream.url = `${ADDON_HOST}/realdebrid/${apiKey}/${stream.infoHash}/${cachedIds}/${stream.fileIdx}`;
delete stream.infoHash;
delete stream.fileIndex;
})
} }
return streams; return streams;