From bcdbadbede613e779d527cb2cde5546c8025fec6 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 7 May 2021 20:17:05 +0200 Subject: [PATCH] Simplify release titles before applying scene naming exception regex filter --- .../Scene/SceneMappingService.cs | 4 ++- src/NzbDrone.Core/Parser/Parser.cs | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs index a87f5b374..dd088f851 100644 --- a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -231,7 +231,9 @@ namespace NzbDrone.Core.DataAugmentation.Scene return normalCandidates; } - filteredCandidates = filteredCandidates.Where(v => Regex.IsMatch(releaseTitle, v.FilterRegex)).ToList(); + var simpleTitle = Parser.Parser.SimplifyTitle(releaseTitle); + + filteredCandidates = filteredCandidates.Where(v => Regex.IsMatch(simpleTitle, v.FilterRegex)).ToList(); if (filteredCandidates.Any()) { diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 170698991..857b640b4 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -469,6 +469,32 @@ namespace NzbDrone.Core.Parser return result; } + public static string SimplifyTitle(string title) + { + if (!ValidateBeforeParsing(title)) return title; + + Logger.Debug("Parsing string '{0}'", title); + + if (ReversedTitleRegex.IsMatch(title)) + { + var titleWithoutExtension = RemoveFileExtension(title).ToCharArray(); + Array.Reverse(titleWithoutExtension); + + title = new string(titleWithoutExtension) + title.Substring(titleWithoutExtension.Length); + + Logger.Debug("Reversed name detected. Converted to '{0}'", title); + } + + var simpleTitle = title; + + simpleTitle = WebsitePrefixRegex.Replace(simpleTitle); + simpleTitle = WebsitePostfixRegex.Replace(simpleTitle); + + simpleTitle = CleanTorrentSuffixRegex.Replace(simpleTitle); + + return simpleTitle; + } + public static ParsedEpisodeInfo ParseTitle(string title) { try