[scraper] detects and handles disk torrents

This commit is contained in:
TheBeastLT
2020-05-12 09:15:26 +02:00
parent eb2b831a7c
commit f4740694a0
2 changed files with 21 additions and 2 deletions

View File

@@ -35,6 +35,12 @@ const SUBTITLE_EXTENSIONS = [
"idx", "idx",
"vtt" "vtt"
]; ];
const DISK_EXTENSIONS = [
"iso",
"m2ts",
"ts",
"vob"
]
function isVideo(filename) { function isVideo(filename) {
return isExtension(filename, VIDEO_EXTENSIONS); return isExtension(filename, VIDEO_EXTENSIONS);
@@ -44,9 +50,13 @@ function isSubtitle(filename) {
return isExtension(filename, SUBTITLE_EXTENSIONS); return isExtension(filename, SUBTITLE_EXTENSIONS);
} }
function isDisk(filename) {
return isExtension(filename, DISK_EXTENSIONS);
}
function isExtension(filename, extensions) { function isExtension(filename, extensions) {
const extensionMatch = filename.match(/\.(\w{2,4})$/); const extensionMatch = filename.match(/\.(\w{2,4})$/);
return extensionMatch && extensions.includes(extensionMatch[1].toLowerCase()); return extensionMatch && extensions.includes(extensionMatch[1].toLowerCase());
} }
module.exports = { isVideo, isSubtitle } module.exports = { isVideo, isSubtitle, isDisk }

View File

@@ -5,6 +5,7 @@ const Promises = require('../lib/promises');
const { torrentFiles } = require('../lib/torrent'); const { torrentFiles } = require('../lib/torrent');
const { getMetadata, getImdbId, getKitsuId } = require('../lib/metadata'); const { getMetadata, getImdbId, getKitsuId } = require('../lib/metadata');
const { Type } = require('./types'); const { Type } = require('./types');
const { isDisk } = require('./extension');
const MIN_SIZE = 10 * 1024 * 1024; // 10 MB const MIN_SIZE = 10 * 1024 * 1024; // 10 MB
const MULTIPLE_FILES_SIZE = 4 * 1024 * 1024 * 1024; // 4 GB const MULTIPLE_FILES_SIZE = 4 * 1024 * 1024 * 1024; // 4 GB
@@ -79,13 +80,17 @@ async function parseSeriesFiles(torrent, parsedName, metadata) {
async function getMoviesTorrentContent(torrent, parsedName) { async function getMoviesTorrentContent(torrent, parsedName) {
const hasMultipleMovie = parsedName.complete || typeof parsedName.year === 'string'; const hasMultipleMovie = parsedName.complete || typeof parsedName.year === 'string';
return torrentFiles(torrent) const files = await torrentFiles(torrent)
.catch(error => { .catch(error => {
if (!hasMultipleMovie) { if (!hasMultipleMovie) {
return { videos: [{ name: torrent.title, path: torrent.title, size: torrent.size }] } return { videos: [{ name: torrent.title, path: torrent.title, size: torrent.size }] }
} }
return Promise.reject(error); return Promise.reject(error);
}); });
if (files.contents && files.contents.length && !files.length && isDiskTorrent(files.contents)) {
files.videos = [{ name: torrent.title, path: torrent.title, size: torrent.size }];
}
return files;
} }
async function getSeriesTorrentContent(torrent, parsedName) { async function getSeriesTorrentContent(torrent, parsedName) {
@@ -383,6 +388,10 @@ function findMovieKitsuId(title) {
return getKitsuId(parsedTitle, Type.MOVIE).catch(() => undefined); return getKitsuId(parsedTitle, Type.MOVIE).catch(() => undefined);
} }
function isDiskTorrent(contents) {
return contents.some(content => isDisk(content));
}
function isSingleMovie(videos) { function isSingleMovie(videos) {
return videos.length === 1 || return videos.length === 1 ||
(videos.length === 2 && (videos.length === 2 &&