potentially resolve RD downloads items metadata
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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`;
|
||||
|
||||
@@ -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 }]
|
||||
|
||||
Reference in New Issue
Block a user