moves movies ids inside torrent object
This commit is contained in:
@@ -5,10 +5,11 @@ const { Type } = require('./types');
|
||||
|
||||
const MIN_SIZE = 20 * 1024 * 1024; // 20 MB
|
||||
|
||||
async function parseTorrentFiles(torrent, imdbId, kitsuId) {
|
||||
async function parseTorrentFiles(torrent) {
|
||||
const parsedTorrentName = parse(torrent.title);
|
||||
parsedTorrentName.hasMovies = parsedTorrentName.complete || !!torrent.title.match(/movies?(?:\W|$)/);
|
||||
const metadata = await getMetadata(kitsuId || imdbId, torrent.type || Type.MOVIE).catch(() => undefined);
|
||||
const metadata = await getMetadata(torrent.kitsuId || torrent.imdbId, torrent.type || Type.MOVIE)
|
||||
.catch(() => undefined);
|
||||
|
||||
// if (metadata && metadata.type !== torrent.type && torrent.type !== Type.ANIME) {
|
||||
// throw new Error(`Mismatching entry type for ${torrent.name}: ${torrent.type}!=${metadata.type}`);
|
||||
@@ -37,8 +38,8 @@ async function parseTorrentFiles(torrent, imdbId, kitsuId) {
|
||||
infoHash: torrent.infoHash,
|
||||
title: torrent.title,
|
||||
size: torrent.size,
|
||||
imdbId: imdbId || metadata && metadata.imdb_id,
|
||||
kitsuId: kitsuId || metadata && metadata.kitsu_id
|
||||
imdbId: torrent.imdbId || metadata && metadata.imdb_id,
|
||||
kitsuId: torrent.kitsuId || metadata && metadata.kitsu_id
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -49,8 +50,8 @@ async function parseTorrentFiles(torrent, imdbId, kitsuId) {
|
||||
.then((files) => decomposeEpisodes(torrent, files, metadata))
|
||||
.then((files) => assignKitsuOrImdbEpisodes(files, metadata))
|
||||
.then((files) => Promise.all(files.map(file => file.isMovie
|
||||
? mapSeriesMovie(file, torrent.infoHash)
|
||||
: mapSeriesEpisode(file, torrent.infoHash, imdbId, kitsuId))))
|
||||
? mapSeriesMovie(file, torrent)
|
||||
: mapSeriesEpisode(file, torrent))))
|
||||
.then((files) => files.reduce((a, b) => a.concat(b), []))
|
||||
.catch((error) => {
|
||||
console.log(`Failed getting files for ${torrent.title}`, error.message);
|
||||
@@ -70,27 +71,27 @@ async function getSeriesFiles(torrent, parsedTorrentName) {
|
||||
return torrentFiles(torrent);
|
||||
}
|
||||
|
||||
async function mapSeriesEpisode(file, infoHash, imdbId, kitsuId) {
|
||||
async function mapSeriesEpisode(file, torrent) {
|
||||
if (!file.episodes && !file.kitsuEpisodes) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
const episodeIndexes = [...(file.episodes || file.kitsuEpisodes).keys()];
|
||||
return Promise.resolve(episodeIndexes.map((index) => ({
|
||||
infoHash: infoHash,
|
||||
infoHash: torrent.infoHash,
|
||||
fileIndex: file.fileIndex,
|
||||
title: file.path || file.name,
|
||||
size: file.size,
|
||||
imdbId: imdbId || file.imdbId,
|
||||
imdbId: torrent.imdbId || file.imdbId,
|
||||
imdbSeason: file.season,
|
||||
imdbEpisode: file.episodes && file.episodes[index],
|
||||
kitsuId: kitsuId || file.kitsuId,
|
||||
kitsuId: torrent.kitsuId || file.kitsuId,
|
||||
kitsuEpisode: file.kitsuEpisodes && file.kitsuEpisodes[index]
|
||||
})))
|
||||
}
|
||||
|
||||
async function mapSeriesMovie(file, infoHash) {
|
||||
async function mapSeriesMovie(file, torrent) {
|
||||
return findMovieImdbId(file).then((imdbId) => [{
|
||||
infoHash: infoHash,
|
||||
infoHash: torrent.infoHash,
|
||||
fileIndex: file.fileIndex,
|
||||
title: file.name,
|
||||
size: file.size,
|
||||
|
||||
Reference in New Issue
Block a user