From ccc2c39d4347e02121c7ea325ae27f82d51a7054 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 27 Apr 2019 16:15:00 -0700 Subject: [PATCH] Fixed: Cleaning percent signs from release names Fixes #1998 --- .../ParserTests/NormalizeTitleFixture.cs | 8 ++++++++ src/NzbDrone.Core/Parser/Parser.cs | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs b/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs index 6e2b01366..d5701186f 100644 --- a/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs @@ -134,5 +134,13 @@ namespace NzbDrone.Core.Test.ParserTests { "Tokyo Ghoul A".CleanSeriesTitle().Should().Be("tokyoghoula"); } + + [TestCase("3%", "3percent")] + [TestCase("Teen Top & 100% Outing Brothers", "teentop100percentoutingbrothers")] + [TestCase("Big Jay Oakerson's What's Your F@%king Deal?!", "bigjayoakersonswhatsyourfkingdeal")] + public void should_replace_percent_sign_with_percent_following_numbers(string input, string expected) + { + input.CleanSeriesTitle().Should().Be(expected); + } } } diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index bc732dae1..f6f07005c 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -310,6 +310,8 @@ namespace NzbDrone.Core.Parser string.Empty, RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex PercentRegex = new Regex(@"(?<=\b\d+)%", RegexOptions.Compiled); + private static readonly Regex FileExtensionRegex = new Regex(@"\.[a-z0-9]{2,4}$", RegexOptions.IgnoreCase | RegexOptions.Compiled); @@ -528,6 +530,9 @@ namespace NzbDrone.Core.Parser if (long.TryParse(title, out number)) return title; + // Replace `%` with `percent` to deal with the 3% case + title = PercentRegex.Replace(title, "percent"); + return NormalizeRegex.Replace(title).ToLower().RemoveAccent(); }