From b34e0f8259b8e1f0b5bdf6bc9a891350ffbad273 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 26 Feb 2024 21:33:07 -0800 Subject: [PATCH] Fixed: Ignore language in split episode title --- .../NormalizeEpisodeTitleFixture.cs | 23 +++++++++++++++++++ ...ture.cs => NormalizeSeriesTitleFixture.cs} | 2 +- src/NzbDrone.Core/Parser/Parser.cs | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core.Test/ParserTests/NormalizeEpisodeTitleFixture.cs rename src/NzbDrone.Core.Test/ParserTests/{NormalizeTitleFixture.cs => NormalizeSeriesTitleFixture.cs} (98%) diff --git a/src/NzbDrone.Core.Test/ParserTests/NormalizeEpisodeTitleFixture.cs b/src/NzbDrone.Core.Test/ParserTests/NormalizeEpisodeTitleFixture.cs new file mode 100644 index 000000000..1f94af578 --- /dev/null +++ b/src/NzbDrone.Core.Test/ParserTests/NormalizeEpisodeTitleFixture.cs @@ -0,0 +1,23 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.ParserTests +{ + [TestFixture] + public class NormalizeEpisodeTitleFixture : CoreTest + { + [TestCase("Episode Title", "episode title")] + [TestCase("A.B,C;", "a b c")] + [TestCase("Episode Title", "episode title")] + [TestCase("French Title (1)", "french title")] + [TestCase("Series.Title.S01.Special.Episode.Title.720p.HDTV.x264-Sonarr", "episode title")] + [TestCase("Series.Title.S01E00.Episode.Title.720p.HDTV.x264-Sonarr", "episode title")] + public void should_normalize_episode_title(string input, string expected) + { + var result = Parser.Parser.NormalizeEpisodeTitle(input); + + result.Should().Be(expected); + } + } +} diff --git a/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs b/src/NzbDrone.Core.Test/ParserTests/NormalizeSeriesTitleFixture.cs similarity index 98% rename from src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs rename to src/NzbDrone.Core.Test/ParserTests/NormalizeSeriesTitleFixture.cs index 8131efcd1..4c9b683b6 100644 --- a/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/NormalizeSeriesTitleFixture.cs @@ -6,7 +6,7 @@ using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.ParserTests { [TestFixture] - public class NormalizeTitleFixture : CoreTest + public class NormalizeSeriesTitleFixture : CoreTest { [TestCase("Series", "series")] [TestCase("Series (2009)", "series2009")] diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index fd040a17b..421ca70cf 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -541,6 +541,7 @@ namespace NzbDrone.Core.Parser private static readonly Regex TitleComponentsRegex = new Regex(@"^(?:(?.+?) \((?<title>.+?)\)|(?<title>.+?) \| (?<title>.+?))$", RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex PartRegex = new Regex(@"\(\d+\)$", RegexOptions.Compiled); private static readonly Regex PunctuationRegex = new Regex(@"[^\w\s]", RegexOptions.Compiled); private static readonly Regex ArticleWordRegex = new Regex(@"^(a|an|the)\s", RegexOptions.IgnoreCase | RegexOptions.Compiled); private static readonly Regex SpecialEpisodeWordRegex = new Regex(@"\b(part|special|edition|christmas)\b\s?", RegexOptions.IgnoreCase | RegexOptions.Compiled); @@ -792,6 +793,7 @@ namespace NzbDrone.Core.Parser // Disabled, Until we run into specific testcases for the removal of these words. // title = SpecialEpisodeWordRegex.Replace(title, string.Empty); + title = PartRegex.Replace(title, ""); title = PunctuationRegex.Replace(title, " "); title = DuplicateSpacesRegex.Replace(title, " ");