From 0fe24539625f8397dfb63d4618611db99c3c137a Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 7 Mar 2021 16:53:56 -0800 Subject: [PATCH] Fixed: Parsing similar series titles with common words at end --- .../ParserTests/NormalizeTitleFixture.cs | 28 +++++++++++++++---- .../ParserTests/SingleEpisodeParserFixture.cs | 1 + src/NzbDrone.Core/Parser/Parser.cs | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs b/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs index 13189c402..a18a63ba8 100644 --- a/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs @@ -36,16 +36,13 @@ public void should_remove_special_characters_and_casing(string dirty, string cle [TestCase("or")] [TestCase("an")] [TestCase("of")] - public void should_remove_common_words(string word) + public void should_remove_common_words_from_middle_of_title(string word) { var dirtyFormat = new[] { "word.{0}.word", "word {0} word", - "word-{0}-word", - "word.word.{0}", - "word-word-{0}", - "word-word {0}", + "word-{0}-word" }; foreach (var s in dirtyFormat) @@ -55,6 +52,27 @@ public void should_remove_common_words(string word) } } + [TestCase("the")] + [TestCase("and")] + [TestCase("or")] + [TestCase("an")] + [TestCase("of")] + public void should_not_remove_common_words_from_end_of_title(string word) + { + var dirtyFormat = new[] + { + "word.word.{0}", + "word-word-{0}", + "word-word {0}" + }; + + foreach (var s in dirtyFormat) + { + var dirty = string.Format(s, word); + dirty.CleanSeriesTitle().Should().Be("wordword" + word.ToLower()); + } + } + [Test] public void should_remove_a_from_middle_of_title() { diff --git a/src/NzbDrone.Core.Test/ParserTests/SingleEpisodeParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/SingleEpisodeParserFixture.cs index 761aea439..872f4e362 100644 --- a/src/NzbDrone.Core.Test/ParserTests/SingleEpisodeParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/SingleEpisodeParserFixture.cs @@ -142,6 +142,7 @@ public class SingleEpisodeParserFixture : CoreTest [TestCase("tvs-amgo-dd51-dl-7p-azhd-x264-103", "tvs-amgo-dd51-dl-7p-azhd", 1, 3)] [TestCase("Series Title - S01E01 [AC3 5.1 Castellano][www.descargas2020.org]", "Series Title", 1, 1)] [TestCase("Series Title - [02x01] - Episode 1", "Series Title", 2, 1)] + [TestCase("Series.Title.Of.S01E01.xyz", "Series Title Of", 1, 1)] //[TestCase("", "", 0, 0)] public void should_parse_single_episode(string postTitle, string title, int seasonNumber, int episodeNumber) { diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 73dfbf29e..c4429af21 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -368,7 +368,7 @@ public static class Parser //Regex to detect whether the title was reversed. private static readonly Regex ReversedTitleRegex = new Regex(@"(?:^|[-._ ])(p027|p0801|\d{2,3}E\d{2}S)[-._ ]", RegexOptions.Compiled); - private static readonly RegexReplace NormalizeRegex = new RegexReplace(@"((?:\b|_)(?