diff --git a/scraper/lib/repository.js b/scraper/lib/repository.js index 07183c5..62fb6d6 100644 --- a/scraper/lib/repository.js +++ b/scraper/lib/repository.js @@ -176,6 +176,10 @@ function getTorrentsBasedOnQuery(where) { return Torrent.findAll({ where: where }); } +function getFilesBasedOnQuery(where) { + return File.findAll({ where: where }); +} + function getTorrentsWithoutSize() { return Torrent.findAll({ where: literal( @@ -325,6 +329,7 @@ module.exports = { getTorrent, getTorrentsBasedOnTitle, getTorrentsBasedOnQuery, + getFilesBasedOnQuery, deleteTorrent, getUpdateSeedersTorrents, getUpdateSeedersNewTorrents, diff --git a/scraper/lib/torrentFiles.js b/scraper/lib/torrentFiles.js index b82cf16..ab5eda7 100644 --- a/scraper/lib/torrentFiles.js +++ b/scraper/lib/torrentFiles.js @@ -247,18 +247,18 @@ function isAbsoluteEpisodeFiles(torrent, files, metadata) { .filter(file => file.episodes.every(ep => metadata.episodeCount[file.season - 1] < ep)) return nonMovieEpisodes.every(file => !file.season) || (isAnime && nonMovieEpisodes.every(file => file.season > metadata.episodeCount.length)) - || absoluteEpisodes.length >= threshold - // && !isNewEpisodesNotInMetadata(files, metadata); + || absoluteEpisodes.length >= threshold; } -function isNewEpisodesNotInMetadata(files, metadata) { +function isNewEpisodeNotInMetadata(torrent, file, metadata) { // new episode might not yet been indexed by cinemeta. // detect this if episode number is larger than the last episode or season is larger than the last one - return files.length === 1 + // only for non anime metas + const isAnime = torrent.type === Type.ANIME && torrent.kitsuId; + return !isAnime && !file.isMovie && file.episodes && file.season !== 1 && /continuing|current/i.test(metadata.status) - && files.filter(file => !file.isMovie && file.episodes) - .every(file => file.season >= metadata.episodeCount.length - && file.episodes.every(ep => ep > metadata.episodeCount[file.season - 1])) + && file.season >= metadata.episodeCount.length + && file.episodes.every(ep => ep > (metadata.episodeCount[file.season - 1] || 0)); } function decomposeConcatSeasonAndEpisodeFiles(torrent, files, metadata) { @@ -284,6 +284,7 @@ function decomposeAbsoluteEpisodeFiles(torrent, files, metadata) { } files .filter(file => file.episodes && !file.isMovie && file.season !== 0) + .filter(file => !isNewEpisodeNotInMetadata(torrent, file, metadata)) .filter(file => !file.season || (metadata.episodeCount[file.season - 1] || 0) < file.episodes[0]) .forEach(file => { const seasonIdx = ([...metadata.episodeCount.keys()]