From 34486230ea7f650fb5bada13666a239c01db5687 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Sat, 28 Mar 2020 23:18:51 +0100 Subject: [PATCH] [scraper] updates movie title to path --- package-lock.json | 4 ++-- package.json | 2 +- scraper/lib/torrentFiles.js | 15 ++++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6726c11..b56a307 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1620,8 +1620,8 @@ } }, "parse-torrent-title": { - "version": "git://github.com/TheBeastLT/parse-torrent-title.git#7597effa105bc1f0329a88aefea2291f2f7f11c1", - "from": "git://github.com/TheBeastLT/parse-torrent-title.git#7597effa105bc1f0329a88aefea2291f2f7f11c1", + "version": "git://github.com/TheBeastLT/parse-torrent-title.git#826ee1a8a832e8c18fcc0703f5b56a8b9acd4283", + "from": "git://github.com/TheBeastLT/parse-torrent-title.git#826ee1a8a832e8c18fcc0703f5b56a8b9acd4283", "requires": { "moment": "^2.24.0" } diff --git a/package.json b/package.json index a938666..5fbf3b0 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "node-schedule": "^1.3.2", "nodejs-bing": "^0.1.0", "parse-torrent": "^6.1.2", - "parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#7597effa105bc1f0329a88aefea2291f2f7f11c1", + "parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#826ee1a8a832e8c18fcc0703f5b56a8b9acd4283", "peer-search": "^0.6.x", "pg": "^7.8.2", "pg-hstore": "^2.3.2", diff --git a/scraper/lib/torrentFiles.js b/scraper/lib/torrentFiles.js index b790182..4c931f8 100644 --- a/scraper/lib/torrentFiles.js +++ b/scraper/lib/torrentFiles.js @@ -30,7 +30,7 @@ async function parseTorrentFiles(torrent) { .then((newImdbId) => ({ infoHash: torrent.infoHash, fileIndex: file.fileIndex, - title: file.name, + title: file.path || file.name, size: file.size, imdbId: newImdbId, }))))) @@ -113,7 +113,7 @@ async function mapSeriesMovie(file, torrent) { return findMovieImdbId(file).then((imdbId) => [{ infoHash: torrent.infoHash, fileIndex: file.fileIndex, - title: file.name, + title: file.path || file.name, size: file.size, imdbId: imdbId }]) @@ -122,13 +122,14 @@ async function mapSeriesMovie(file, torrent) { function parseSeriesFile(file, parsedTorrentName) { const fileInfo = parse(file.name); // the episode may be in a folder containing season number - if (!fileInfo.season && parsedTorrentName.season) { - fileInfo.season = parsedTorrentName.season; - } else if (!fileInfo.season && file.path.includes('/')) { + if (!fileInfo.season && file.path.includes('/')) { const folders = file.path.split('/'); const pathInfo = parse(folders[folders.length - 2]); fileInfo.season = pathInfo.season; } + if (!fileInfo.season && parsedTorrentName.season) { + fileInfo.season = parsedTorrentName.season; + } // force episode to any found number if it was not parsed if (!fileInfo.episodes && !fileInfo.date) { const epMatcher = fileInfo.title.match(/(? !file.season) + // .filter(file => !file.season) .map(file => { - const episodeTitle = file.name.replace(/^.*-\s?(.+)\.\w{1,4}$/, '$1').trim(); + const episodeTitle = file.name.replace('_', ' ').replace(/^.*(?:E\d+[abc]?|-)\s?(.+)\.\w{1,4}$/, '$1').trim(); const foundEpisode = metadata.videos .map(video => ({ ...video, distance: distance(episodeTitle, video.name) })) .sort((a, b) => b.distance - a.distance)[0];