1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

Fixed: Parsing similar movie titles with common words at end

This commit is contained in:
Mark McDowall 2021-03-07 16:53:56 -08:00 committed by Qstick
parent 53a9c849cb
commit 691a8955fe
2 changed files with 24 additions and 6 deletions

View File

@ -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()
{

View File

@ -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|_)(?<!^|[^a-zA-Z0-9_']\w[^a-zA-Z0-9_'])(a(?!$|[^a-zA-Z0-9_']\w[^a-zA-Z0-9_'])|an|the|and|or|of)(?:\b|_))|\W|_",
private static readonly Regex NormalizeRegex = new Regex(@"((?:\b|_)(?<!^|[^a-zA-Z0-9_']\w[^a-zA-Z0-9_'])(a(?!$|[^a-zA-Z0-9_']\w[^a-zA-Z0-9_'])|an|the|and|or|of)(?!$)(?:\b|_))|\W|_",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex FileExtensionRegex = new Regex(@"\.[a-z0-9]{2,4}$",