From f4740694a06da817aaa07532e7a094cef8a3b620 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Tue, 12 May 2020 09:15:26 +0200 Subject: [PATCH] [scraper] detects and handles disk torrents --- scraper/lib/extension.js | 12 +++++++++++- scraper/lib/torrentFiles.js | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/scraper/lib/extension.js b/scraper/lib/extension.js index 99b7523..ec0e7d7 100644 --- a/scraper/lib/extension.js +++ b/scraper/lib/extension.js @@ -35,6 +35,12 @@ const SUBTITLE_EXTENSIONS = [ "idx", "vtt" ]; +const DISK_EXTENSIONS = [ + "iso", + "m2ts", + "ts", + "vob" +] function isVideo(filename) { return isExtension(filename, VIDEO_EXTENSIONS); @@ -44,9 +50,13 @@ function isSubtitle(filename) { return isExtension(filename, SUBTITLE_EXTENSIONS); } +function isDisk(filename) { + return isExtension(filename, DISK_EXTENSIONS); +} + function isExtension(filename, extensions) { const extensionMatch = filename.match(/\.(\w{2,4})$/); return extensionMatch && extensions.includes(extensionMatch[1].toLowerCase()); } -module.exports = { isVideo, isSubtitle } \ No newline at end of file +module.exports = { isVideo, isSubtitle, isDisk } \ No newline at end of file diff --git a/scraper/lib/torrentFiles.js b/scraper/lib/torrentFiles.js index 0ece7db..4e17d9f 100644 --- a/scraper/lib/torrentFiles.js +++ b/scraper/lib/torrentFiles.js @@ -5,6 +5,7 @@ const Promises = require('../lib/promises'); const { torrentFiles } = require('../lib/torrent'); const { getMetadata, getImdbId, getKitsuId } = require('../lib/metadata'); const { Type } = require('./types'); +const { isDisk } = require('./extension'); const MIN_SIZE = 10 * 1024 * 1024; // 10 MB 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) { const hasMultipleMovie = parsedName.complete || typeof parsedName.year === 'string'; - return torrentFiles(torrent) + const files = await torrentFiles(torrent) .catch(error => { if (!hasMultipleMovie) { return { videos: [{ name: torrent.title, path: torrent.title, size: torrent.size }] } } 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) { @@ -383,6 +388,10 @@ function findMovieKitsuId(title) { return getKitsuId(parsedTitle, Type.MOVIE).catch(() => undefined); } +function isDiskTorrent(contents) { + return contents.some(content => isDisk(content)); +} + function isSingleMovie(videos) { return videos.length === 1 || (videos.length === 2 &&