[scraper] fixes featurette and redundant files detection

This commit is contained in:
TheBeastLT
2020-05-07 10:10:21 +02:00
parent 6bed8bad34
commit 3b2617cd3c
2 changed files with 21 additions and 20 deletions

View File

@@ -123,17 +123,17 @@ function filesAndSizeFromTorrentStream(torrent, timeout = 30000) {
} }
function filterVideos(files) { function filterVideos(files) {
const maxSize = Math.max(...files.map(file => file.size)); const videos = files.filter(file => isVideo(file.path));
const minSampleRatio = files.length <= 3 ? 5 : 10; const maxSize = Math.max(...videos.map(video => video.size));
const minRedundantRatio = files.length <= 3 ? 30 : Number.MAX_VALUE; const minSampleRatio = videos.length <= 3 ? 5 : 10;
const isSample = file => file.path.match(/sample/i) && maxSize / parseInt(file.size) > minSampleRatio; const minRedundantRatio = videos.length <= 3 ? 30 : Number.MAX_VALUE;
const isRedundant = file => maxSize / parseInt(file.size) > minRedundantRatio; const isSample = video => video.path.match(/sample/i) && maxSize / parseInt(video.size) > minSampleRatio;
const isExtra = file => file.path.match(/extras?\//i); const isRedundant = video => maxSize / parseInt(video.size) > minRedundantRatio;
return files const isExtra = video => video.path.match(/extras?\//i);
.filter(file => isVideo(file.path)) return videos
.filter(file => !isSample(file)) .filter(video => !isSample(video))
.filter(file => !isExtra(file)) .filter(video => !isExtra(video))
.filter(file => !isRedundant(file)); .filter(video => !isRedundant(video));
} }
function filterSubtitles(files) { function filterSubtitles(files) {

View File

@@ -47,15 +47,16 @@ async function parseMovieFiles(torrent, parsedName, metadata) {
} }
const parsedVideos = await Promises.sequence(filteredVideos const parsedVideos = await Promises.sequence(filteredVideos
.map(video => () => findMovieImdbId(video.name) .map(video => () => isFeaturette(video)
.then(newImdbId => ({ ? Promise.resolve(video)
infoHash: torrent.infoHash, : findMovieImdbId(video.name).then(imdbId => ({ ...video, imdbId }))))
fileIndex: video.fileIndex, .then(videos => videos.map(video => ({
title: video.path || video.name, infoHash: torrent.infoHash,
size: video.size, fileIndex: video.fileIndex,
imdbId: newImdbId, title: video.path || video.name,
}))) size: video.size,
.map(video => isFeaturette(video) ? clearInfoFields(video) : video)); imdbId: video.imdbId,
})));
return { contents, videos: parsedVideos, subtitles }; return { contents, videos: parsedVideos, subtitles };
} }