Skip to content

Commit 7db56d7

Browse files
committed
fix: swap trailing determiners at the end of titles
fixes Radarr#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'.
1 parent a0dd26c commit 7db56d7

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/NzbDrone.Common/Extensions/StringExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace NzbDrone.Common.Extensions
1212
public static class StringExtensions
1313
{
1414
private static readonly Regex CamelCaseRegex = new Regex("(?<!^)[A-Z]", RegexOptions.Compiled);
15+
private static readonly Regex TrailingDeterminerRegex = new Regex("(, The)$|(, A)$", RegexOptions.Compiled);
1516

1617
public static string NullSafe(this string target)
1718
{
@@ -228,5 +229,18 @@ public static string Reverse(this string text)
228229

229230
return new string(array);
230231
}
232+
233+
// Some files have their determiner (The, A) at the end of the title to help sorting, flip them back to prevent searching errors.
234+
public static string SwapTrailingDeterminers(this string input)
235+
{
236+
var match = TrailingDeterminerRegex.Match(input);
237+
if (match.Success)
238+
{
239+
input = TrailingDeterminerRegex.Replace(input, string.Empty);
240+
input = match.Value.Replace(", ", string.Empty) + " " + input;
241+
}
242+
243+
return input;
244+
}
231245
}
232246
}

src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,17 @@ public void should_not_clean_trailing_a()
186186
{
187187
"Tokyo Ghoul A".CleanMovieTitle().Should().Be("tokyoghoula");
188188
}
189+
190+
[TestCase("Prestige, The", "theprestige")]
191+
[TestCase("Prestige, A", "aprestige")]
192+
[TestCase("Crow, The", "thecrow")]
193+
[TestCase("Crow, A", "acrow")]
194+
[TestCase("Beautiful Romance, The", "thebeautifulromance")]
195+
[TestCase("Beautiful Romance, A", "abeautifulromance")]
196+
public void should_swap_determiner(string parsedSeriesName, string seriesName)
197+
{
198+
var result = parsedSeriesName.CleanMovieTitle();
199+
result.Should().Be(seriesName);
200+
}
189201
}
190202
}

src/NzbDrone.Core/Parser/Parser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public static string CleanMovieTitle(this string title)
466466
return title;
467467
}
468468

469-
return ReplaceGermanUmlauts(NormalizeRegex.Replace(title, string.Empty).ToLower()).RemoveAccent();
469+
return ReplaceGermanUmlauts(NormalizeRegex.Replace(title.SwapTrailingDeterminers(), string.Empty).ToLower()).RemoveAccent();
470470
}
471471

472472
public static string NormalizeEpisodeTitle(this string title)

0 commit comments

Comments
 (0)