mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
potentially resolve RD downloads items metadata
This commit is contained in:
@@ -48,8 +48,8 @@ function getTorrent(infoHash) {
|
|||||||
return Torrent.findOne({ where: { infoHash: infoHash } });
|
return Torrent.findOne({ where: { infoHash: infoHash } });
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTorrentWithFiles(infoHash) {
|
function getFiles(infoHashes) {
|
||||||
return Torrent.findOne({ where: { infoHash: infoHash }, include: [File] });
|
return File.findAll({ where: { infoHash: { [Op.in]: infoHashes} } });
|
||||||
}
|
}
|
||||||
|
|
||||||
function getImdbIdMovieEntries(imdbId) {
|
function getImdbIdMovieEntries(imdbId) {
|
||||||
@@ -109,7 +109,7 @@ function getKitsuIdSeriesEntries(kitsuId, episode) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getTorrent,
|
getTorrent,
|
||||||
getTorrentWithFiles,
|
getFiles,
|
||||||
getImdbIdMovieEntries,
|
getImdbIdMovieEntries,
|
||||||
getImdbIdSeriesEntries,
|
getImdbIdSeriesEntries,
|
||||||
getKitsuIdMovieEntries,
|
getKitsuIdMovieEntries,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
const repository = require('../lib/repository')
|
const repository = require('../lib/repository')
|
||||||
const { Type } = require("../lib/types");
|
|
||||||
|
|
||||||
const METAHUB_URL = 'https://images.metahub.space'
|
const METAHUB_URL = 'https://images.metahub.space'
|
||||||
const BadTokenError = { code: 'BAD_TOKEN' }
|
const BadTokenError = { code: 'BAD_TOKEN' }
|
||||||
@@ -21,22 +20,25 @@ function streamFilename(stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function enrichMeta(itemMeta) {
|
async function enrichMeta(itemMeta) {
|
||||||
const torrent = itemMeta.infoHash && await repository.getTorrentWithFiles(itemMeta.infoHash);
|
const infoHashes = [...new Set([itemMeta.infoHash]
|
||||||
const commonImdbId = torrent && mostCommonValue(torrent.files.map(file => file.imdbId));
|
.concat(itemMeta.videos.map(video => video.infoHash))
|
||||||
if (commonImdbId) {
|
.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 {
|
return {
|
||||||
...itemMeta,
|
...itemMeta,
|
||||||
logo: `${METAHUB_URL}/logo/medium/${commonImdbId}/img`,
|
logo: commonImdbId && `${METAHUB_URL}/logo/medium/${commonImdbId}/img`,
|
||||||
poster: `${METAHUB_URL}/poster/medium/${commonImdbId}/img`,
|
poster: commonImdbId && `${METAHUB_URL}/poster/medium/${commonImdbId}/img`,
|
||||||
background: `${METAHUB_URL}/background/medium/${commonImdbId}/img`,
|
background: commonImdbId && `${METAHUB_URL}/background/medium/${commonImdbId}/img`,
|
||||||
videos: itemMeta.videos.map(video => {
|
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 && file.imdbId) {
|
||||||
if (file.imdbSeason && file.imdbEpisode) {
|
if (file.imdbSeason && file.imdbEpisode) {
|
||||||
video.id = `${file.imdbId}:${file.imdbSeason}:${file.imdbEpisode}`;
|
video.id = `${file.imdbId}:${file.imdbSeason}:${file.imdbEpisode}`;
|
||||||
video.season = file.imdbSeason;
|
video.season = file.imdbSeason;
|
||||||
video.episode = file.imdbEpisode;
|
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 {
|
} else {
|
||||||
video.id = file.imdbId;
|
video.id = file.imdbId;
|
||||||
video.thumbnail = `${METAHUB_URL}/background/small/${file.imdbId}/img`;
|
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 options = await getDefaultOptions(ip);
|
||||||
const RD = new RealDebridClient(apiKey, options);
|
const RD = new RealDebridClient(apiKey, options);
|
||||||
if (itemId === DEBRID_DOWNLOADS) {
|
if (itemId === DEBRID_DOWNLOADS) {
|
||||||
|
// const allTorrents = await _getAllTorrents(RD).catch(() => []);
|
||||||
const videos = await _getAllDownloads(RD)
|
const videos = await _getAllDownloads(RD)
|
||||||
.then(downloads => downloads
|
.then(downloads => downloads
|
||||||
.map(download => ({
|
.map(download => ({
|
||||||
id: `${KEY}:${DEBRID_DOWNLOADS}:${download.id}`,
|
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,
|
title: download.filename,
|
||||||
released: new Date(download.generated).toISOString(),
|
released: new Date(download.generated).toISOString(),
|
||||||
streams: [{ url: download.download }]
|
streams: [{ url: download.download }]
|
||||||
|
|||||||
Reference in New Issue
Block a user