fix: swap trailing determiners at the end of titles

fixes #9815.\n\n Some files have their , A or , The at the end of the file to prevent alphabetical sorting clustering these titles together. This stops working when searching for files inside radarr as a cleaned title will have 'prestigethe' instead of 'theprestige'.
This commit is contained in:
Rohan Chandi 2024-03-05 13:29:41 +01:00
parent a0dd26c353
commit 7db56d7605
3 changed files with 27 additions and 1 deletions

View File

@ -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);
public static string NullSafe(this string target)
{
@ -228,5 +229,18 @@ namespace NzbDrone.Common.Extensions
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;
}
}
}

View File

@ -186,5 +186,17 @@ namespace NzbDrone.Core.Test.ParserTests
{
"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);
}
}
}

View File

@ -466,7 +466,7 @@ namespace NzbDrone.Core.Parser
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)