From 691a8955fee345d37c09da12b451d2488e9ae440 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 7 Mar 2021 16:53:56 -0800 Subject: [PATCH] Fixed: Parsing similar movie titles with common words at end --- .../ParserTests/NormalizeTitleFixture.cs | 28 +++++++++++++++---- src/NzbDrone.Core/Parser/Parser.cs | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs b/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs index 69dde0889..23631b51d 100644 --- a/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs @@ -37,16 +37,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) @@ -56,6 +53,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.CleanMovieTitle().Should().Be("wordword" + word.ToLower()); + } + } + [Test] public void should_remove_a_from_middle_of_title() { diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 86ec89acf..4c45bbd1e 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -100,7 +100,7 @@ public static class Parser // Regex to unbracket alternative titles. private static readonly Regex BracketedAlternativeTitleRegex = new Regex(@"(.*) \([ ]*AKA[ ]+(.*)\)", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex NormalizeRegex = new Regex(@"((?:\b|_)(?