enrich metadata for some debrid providers' metas
This commit is contained in:
@@ -48,6 +48,10 @@ function getTorrent(infoHash) {
|
||||
return Torrent.findOne({ where: { infoHash: infoHash } });
|
||||
}
|
||||
|
||||
function getTorrentWithFiles(infoHash) {
|
||||
return Torrent.findOne({ where: { infoHash: infoHash }, include: [File] });
|
||||
}
|
||||
|
||||
function getImdbIdMovieEntries(imdbId) {
|
||||
return File.findAll({
|
||||
where: {
|
||||
@@ -105,6 +109,7 @@ function getKitsuIdSeriesEntries(kitsuId, episode) {
|
||||
|
||||
module.exports = {
|
||||
getTorrent,
|
||||
getTorrentWithFiles,
|
||||
getImdbIdMovieEntries,
|
||||
getImdbIdSeriesEntries,
|
||||
getKitsuIdMovieEntries,
|
||||
|
||||
@@ -64,6 +64,7 @@ async function getItemMeta(itemId, apiKey) {
|
||||
id: `${KEY}:${torrent.id}`,
|
||||
type: Type.OTHER,
|
||||
name: torrent.filename,
|
||||
infoHash: torrent.hash.toLowerCase(),
|
||||
videos: torrent.links
|
||||
.filter(file => isVideo(file.filename))
|
||||
.map((file, index) => ({
|
||||
|
||||
@@ -60,6 +60,7 @@ async function getItemMeta(itemId, apiKey, ip) {
|
||||
id: `${KEY}:${torrent.id}`,
|
||||
type: Type.OTHER,
|
||||
name: torrent.name,
|
||||
infoHash: torrent.hashString.toLowerCase(),
|
||||
videos: torrent.files
|
||||
.filter(file => isVideo(file.name))
|
||||
.map((file, index) => ({
|
||||
|
||||
@@ -9,7 +9,7 @@ const putio = require('./putio');
|
||||
const StaticResponse = require('./static');
|
||||
const { cacheWrapResolvedUrl } = require('../lib/cache');
|
||||
const { timeout } = require('../lib/promises');
|
||||
const { BadTokenError, streamFilename, AccessDeniedError } = require('./mochHelper');
|
||||
const { BadTokenError, streamFilename, AccessDeniedError, enrichMeta } = require('./mochHelper');
|
||||
|
||||
const RESOLVE_TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
||||
const MIN_API_KEY_SYMBOLS = 15;
|
||||
@@ -125,6 +125,7 @@ async function getMochItemMeta(mochKey, itemId, config) {
|
||||
}
|
||||
|
||||
return moch.instance.getItemMeta(itemId, config[moch.key], config.ip)
|
||||
.then(meta => enrichMeta(meta))
|
||||
.then(meta => {
|
||||
meta.videos
|
||||
.map(video => video.streams)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
const repository = require('../lib/repository')
|
||||
|
||||
const METAHUB_URL = 'https://images.metahub.space'
|
||||
const BadTokenError = { code: 'BAD_TOKEN' }
|
||||
const AccessDeniedError = { code: 'ACCESS_DENIED' }
|
||||
|
||||
@@ -16,4 +19,38 @@ function streamFilename(stream) {
|
||||
return encodeURIComponent(filename)
|
||||
}
|
||||
|
||||
module.exports = { chunkArray, streamFilename, BadTokenError, AccessDeniedError }
|
||||
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) {
|
||||
return {
|
||||
...itemMeta,
|
||||
id: commonImdbId,
|
||||
logo: `${METAHUB_URL}/logo/medium/${commonImdbId}/img`,
|
||||
poster: `${METAHUB_URL}/poster/medium/${commonImdbId}/img`,
|
||||
background: `${METAHUB_URL}/background/medium/${commonImdbId}/img`,
|
||||
videos: itemMeta.videos.map(video => {
|
||||
const file = torrent.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`
|
||||
} else {
|
||||
video.id = file.imdbId;
|
||||
video.thumbnail = `${METAHUB_URL}/background/small/${file.imdbId}/img`;
|
||||
}
|
||||
}
|
||||
return video;
|
||||
})
|
||||
}
|
||||
}
|
||||
return itemMeta
|
||||
}
|
||||
|
||||
function mostCommonValue(array) {
|
||||
return array.sort((a, b) => array.filter(v => v === a).length - array.filter(v => v === b).length).pop();
|
||||
}
|
||||
|
||||
module.exports = { chunkArray, streamFilename, enrichMeta, BadTokenError, AccessDeniedError }
|
||||
|
||||
@@ -147,6 +147,7 @@ async function getItemMeta(itemId, apiKey, ip) {
|
||||
id: `${KEY}:${torrent.id}`,
|
||||
type: Type.OTHER,
|
||||
name: torrent.filename,
|
||||
infoHash: torrent.hash.toLowerCase(),
|
||||
videos: torrent.files
|
||||
.filter(file => file.selected)
|
||||
.filter(file => isVideo(file.path))
|
||||
|
||||
Reference in New Issue
Block a user