From d1d112b97ec787bbf0eb19dae6bba88b84ea7c7c Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Tue, 2 Mar 2021 21:38:58 +0100 Subject: [PATCH] [scraper] update subtitle assignment path parsing --- scraper/lib/torrentSubtitles.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scraper/lib/torrentSubtitles.js b/scraper/lib/torrentSubtitles.js index 76e9944..879c182 100644 --- a/scraper/lib/torrentSubtitles.js +++ b/scraper/lib/torrentSubtitles.js @@ -37,7 +37,7 @@ function _parseVideo(video) { function _mostProbableSubtitleVideos(subtitle, parsedVideos) { const subTitle = (subtitle.title || subtitle.path).split('/').pop().replace(/\.(\w{2,4})$/, ''); - const parsedSub = parseFilename(subTitle); + const parsedSub = parsePath(subtitle.title || subtitle.path); const byFileName = parsedVideos.filter(video => subTitle.includes(video.fileName)); if (byFileName.length === 1) { return byFileName.map(v => v.videoFile); @@ -68,6 +68,12 @@ function singleVideoFile(videos) { return new Set(videos.map(v => v.videoFile.fileIndex)).size === 1; } +function parsePath(path) { + const pathParts = path.split('/').map(part => parseFilename(part)); + const parsedWithEpisode = pathParts.find(parsed => parsed.season && parsed.episodes); + return parsedWithEpisode || pathParts[pathParts.length - 1]; +} + function parseFilename(filename) { const parsedInfo = parse(filename) const titleEpisode = parsedInfo.title.match(/(\d+)$/);