From def60844b2143f038402067eefdd452966c18bc7 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Tue, 25 Apr 2023 22:09:26 +0200 Subject: [PATCH] potentially resolve RD downloads items metadata --- addon/lib/repository.js | 6 +++--- addon/moch/mochHelper.js | 20 +++++++++++--------- addon/moch/realdebrid.js | 4 ++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/addon/lib/repository.js b/addon/lib/repository.js index 7a49be7..245b4a8 100644 --- a/addon/lib/repository.js +++ b/addon/lib/repository.js @@ -48,8 +48,8 @@ function getTorrent(infoHash) { return Torrent.findOne({ where: { infoHash: infoHash } }); } -function getTorrentWithFiles(infoHash) { - return Torrent.findOne({ where: { infoHash: infoHash }, include: [File] }); +function getFiles(infoHashes) { + return File.findAll({ where: { infoHash: { [Op.in]: infoHashes} } }); } function getImdbIdMovieEntries(imdbId) { @@ -109,7 +109,7 @@ function getKitsuIdSeriesEntries(kitsuId, episode) { module.exports = { getTorrent, - getTorrentWithFiles, + getFiles, getImdbIdMovieEntries, getImdbIdSeriesEntries, getKitsuIdMovieEntries, diff --git a/addon/moch/mochHelper.js b/addon/moch/mochHelper.js index 9d9445f..b99991a 100644 --- a/addon/moch/mochHelper.js +++ b/addon/moch/mochHelper.js @@ -1,5 +1,4 @@ const repository = require('../lib/repository') -const { Type } = require("../lib/types"); const METAHUB_URL = 'https://images.metahub.space' const BadTokenError = { code: 'BAD_TOKEN' } @@ -21,22 +20,25 @@ function streamFilename(stream) { } async function enrichMeta(itemMeta) { - const torrent = itemMeta.infoHash && await repository.getTorrentWithFiles(itemMeta.infoHash); - const commonImdbId = torrent && mostCommonValue(torrent.files.map(file => file.imdbId)); - if (commonImdbId) { + const infoHashes = [...new Set([itemMeta.infoHash] + .concat(itemMeta.videos.map(video => video.infoHash)) + .filter(infoHash => infoHash))]; + const files = infoHashes.length ? await repository.getFiles(infoHashes).catch(() => []) : []; + const commonImdbId = itemMeta.infoHash && mostCommonValue(files.map(file => file.imdbId)); + if (files.length) { return { ...itemMeta, - logo: `${METAHUB_URL}/logo/medium/${commonImdbId}/img`, - poster: `${METAHUB_URL}/poster/medium/${commonImdbId}/img`, - background: `${METAHUB_URL}/background/medium/${commonImdbId}/img`, + logo: commonImdbId && `${METAHUB_URL}/logo/medium/${commonImdbId}/img`, + poster: commonImdbId && `${METAHUB_URL}/poster/medium/${commonImdbId}/img`, + background: commonImdbId && `${METAHUB_URL}/background/medium/${commonImdbId}/img`, videos: itemMeta.videos.map(video => { - const file = torrent.files.find(file => video.title.includes(file.title)); + const file = files.find(file => video.title.includes(file.title)); if (file && file.imdbId) { if (file.imdbSeason && file.imdbEpisode) { video.id = `${file.imdbId}:${file.imdbSeason}:${file.imdbEpisode}`; video.season = file.imdbSeason; video.episode = file.imdbEpisode; - video.thumbnail = `https://episodes.metahub.space/${commonImdbId}/${video.season}/${video.episode}/w780.jpg` + video.thumbnail = `https://episodes.metahub.space/${file.imdbId}/${video.season}/${video.episode}/w780.jpg` } else { video.id = file.imdbId; video.thumbnail = `${METAHUB_URL}/background/small/${file.imdbId}/img`; diff --git a/addon/moch/realdebrid.js b/addon/moch/realdebrid.js index 0f0afd1..6fe7588 100644 --- a/addon/moch/realdebrid.js +++ b/addon/moch/realdebrid.js @@ -127,10 +127,14 @@ async function getItemMeta(itemId, apiKey, ip) { const options = await getDefaultOptions(ip); const RD = new RealDebridClient(apiKey, options); if (itemId === DEBRID_DOWNLOADS) { + // const allTorrents = await _getAllTorrents(RD).catch(() => []); const videos = await _getAllDownloads(RD) .then(downloads => downloads .map(download => ({ id: `${KEY}:${DEBRID_DOWNLOADS}:${download.id}`, + // infoHash: allTorrents + // .filter(torrent => (torrent.links || []).find(link => link === download.link)) + // .map(torrent => torrent.hash.toLowerCase())[0], title: download.filename, released: new Date(download.generated).toISOString(), streams: [{ url: download.download }]