mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
enrich metadata for some debrid providers' metas
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user