Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: swap trailing determiners at the end of titles #9820

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/NzbDrone.Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace NzbDrone.Common.Extensions
public static class StringExtensions
{
private static readonly Regex CamelCaseRegex = new Regex("(?<!^)[A-Z]", RegexOptions.Compiled);
private static readonly Regex TrailingDeterminerRegex = new Regex("(, The)$|(, A)$", RegexOptions.Compiled);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static readonly Regex TrailingDeterminerRegex = new Regex("(, The)$|(, A)$", RegexOptions.Compiled);
private static readonly Regex TrailingArticleRegex = new Regex("(, The)$|(, A)$", RegexOptions.Compiled);

Maybe? Food for thought

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty impartial to the naming, but it should be consistent. Want me to change all of the occurrences from determiner to article then?


public static string NullSafe(this string target)
{
Expand Down Expand Up @@ -228,5 +229,18 @@ public static string Reverse(this string text)

return new string(array);
}

// Some files have their determiner (The, A) at the end of the title to help sorting, flip them back to prevent searching errors.
public static string SwapTrailingDeterminers(this string input)
{
var match = TrailingDeterminerRegex.Match(input);
if (match.Success)
{
input = TrailingDeterminerRegex.Replace(input, string.Empty);
input = match.Value.Replace(", ", string.Empty) + " " + input;
}

return input;
}
}
}
12 changes: 12 additions & 0 deletions src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,17 @@ public void should_not_clean_trailing_a()
{
"Tokyo Ghoul A".CleanMovieTitle().Should().Be("tokyoghoula");
}

[TestCase("Prestige, The", "theprestige")]
[TestCase("Prestige, A", "aprestige")]
[TestCase("Crow, The", "thecrow")]
[TestCase("Crow, A", "acrow")]
[TestCase("Beautiful Romance, The", "thebeautifulromance")]
[TestCase("Beautiful Romance, A", "abeautifulromance")]
public void should_swap_determiner(string parsedSeriesName, string seriesName)
{
var result = parsedSeriesName.CleanMovieTitle();
result.Should().Be(seriesName);
}
}
}
2 changes: 1 addition & 1 deletion src/NzbDrone.Core/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public static string CleanMovieTitle(this string title)
return title;
}

return ReplaceGermanUmlauts(NormalizeRegex.Replace(title, string.Empty).ToLower()).RemoveAccent();
return ReplaceGermanUmlauts(NormalizeRegex.Replace(title.SwapTrailingDeterminers(), string.Empty).ToLower()).RemoveAccent();
}

public static string NormalizeEpisodeTitle(this string title)
Expand Down