[scraper] small adjustments

This commit is contained in:
TheBeastLT
2020-11-29 22:23:09 +01:00
parent f78261a889
commit e15b1f3ce9
4 changed files with 28 additions and 9 deletions

View File

@@ -83,7 +83,7 @@ function escapeTitle(title) {
.normalize('NFKD') // normalize non-ASCII characters
.replace(/[\u0300-\u036F]/g, '')
.replace(/&/g, 'and')
.replace(/[;, ~.]+/g, ' ') // replace dots, commas or underscores with spaces
.replace(/[;, ~./]+/g, ' ') // replace dots, commas or underscores with spaces
.replace(/[^\w \-()+#@!']+/g, '') // remove all non-alphanumeric chars
.replace(/\s{2,}/, ' ') // replace multiple spaces
.trim();
@@ -121,7 +121,7 @@ async function getImdbId(info, type) {
}
async function getKitsuId(info) {
const title = escapeTitle(info.title);
const title = escapeTitle(info.title.replace(/\s\|\s.*/, ''));
const year = info.year ? ` ${info.year}` : '';
const season = info.season > 1 ? ` S${info.season}` : '';
const query = `${title}${year}${season}`;

View File

@@ -126,7 +126,7 @@ function filterVideos(files) {
const videos = files.filter(file => isVideo(file.path));
const maxSize = Math.max(...videos.map(video => video.size));
const minSampleRatio = videos.length <= 3 ? 5 : 10;
const minAnimeExtraRatio = 7;
const minAnimeExtraRatio = 5;
const minRedundantRatio = videos.length <= 3 ? 30 : Number.MAX_VALUE;
const isSample = video => video.path.match(/sample/i) && maxSize / parseInt(video.size) > minSampleRatio;
const isRedundant = video => maxSize / parseInt(video.size) > minRedundantRatio;

View File

@@ -160,6 +160,9 @@ async function decomposeEpisodes(torrent, files, metadata = { episodeCount: [] }
// because of imdb season naming/absolute per series naming/multiple seasons
// So in these cases we need to fetch cinemeta based metadata and decompose episodes using that
await updateToCinemetaMetadata(metadata);
files
.filter(file => file.season === undefined && file.episodes)
.forEach(file => file.season = 1);
} else {
// otherwise for anime type episodes are always absolute and for a single season
files
@@ -395,14 +398,15 @@ function needsCinemetaMetadataForAnime(files, metadata) {
return false;
}
const minSeason = Math.min(...metadata.videos.map(video => video.imdbSeason)) || Number.MAX_VALUE;
const maxSeason = Math.max(...metadata.videos.map(video => video.imdbSeason)) || Number.MAX_VALUE;
const differentSeasons = new Set(metadata.videos
.map(video => video.imdbSeason)
.filter(season => Number.isInteger(season))).size;
const totalEpisodes = metadata.totalCount || Number.MAX_VALUE;
const total = metadata.totalCount || Number.MAX_VALUE;
return differentSeasons > 1 || files
.filter(file => !file.isMovie && file.episodes)
.some(file => file.season > maxSeason || file.episodes.every(ep => ep > totalEpisodes));
.some(file => file.season < minSeason || file.season > maxSeason || file.episodes.every(ep => ep > total));
}
async function updateToCinemetaMetadata(metadata) {