1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-06-30 17:43:59 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Rohan Chandiramani (eksrow)
a4a1550bcb
Merge 7db56d7605 into 3a74393d05 2024-06-17 08:03:12 -04:00
Rohan Chandi
7db56d7605 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'.
2024-03-05 13:29:41 +01:00
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 @@ 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;
}
}
}

View File

@ -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);
}
}
}

View File

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