diff --git a/NzbDrone.Core.Test/IndexerTests.cs b/NzbDrone.Core.Test/IndexerTests.cs index d843dac5c..153eea289 100644 --- a/NzbDrone.Core.Test/IndexerTests.cs +++ b/NzbDrone.Core.Test/IndexerTests.cs @@ -708,5 +708,17 @@ namespace NzbDrone.Core.Test parseResults.Should().HaveCount(1); parseResults[0].ReleaseGroup.Should().Be("tvp"); } + + [TestCase("30 Rock", "30%20Rock")] + [TestCase("The Office (US)", "Office%20US")] + [TestCase("Revenge", "Revenge")] + [TestCase(" Top Gear ", "Top%20Gear")] + [TestCase("Breaking Bad", "Breaking%20Bad")] + [TestCase("Top Chef (US)", "Top%20Chef%20US")] + [TestCase("Castle (2009)", "Castle%202009")] + public void newznab_GetQueryTitle_should_return_expected_result(string seriesTitle, string expected) + { + Mocker.Resolve().GetQueryTitle(seriesTitle).Should().Be(expected); + } } } diff --git a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs index f6089a23c..76243629e 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs @@ -18,7 +18,7 @@ namespace NzbDrone.Core.Providers.Indexer private readonly HttpProvider _httpProvider; protected readonly ConfigProvider _configProvider; - private static readonly Regex TitleSearchRegex = new Regex(@"[\W]", RegexOptions.IgnoreCase | RegexOptions.Compiled); + protected static readonly Regex TitleSearchRegex = new Regex(@"[\W]", RegexOptions.IgnoreCase | RegexOptions.Compiled); protected static readonly Regex RemoveThe = new Regex(@"^the\s", RegexOptions.IgnoreCase | RegexOptions.Compiled); [Inject] diff --git a/NzbDrone.Core/Providers/Indexer/Newznab.cs b/NzbDrone.Core/Providers/Indexer/Newznab.cs index 89c3cb597..e3c6ba49a 100644 --- a/NzbDrone.Core/Providers/Indexer/Newznab.cs +++ b/NzbDrone.Core/Providers/Indexer/Newznab.cs @@ -129,5 +129,21 @@ namespace NzbDrone.Core.Providers.Indexer var hostname = item.Links[0].Uri.DnsSafeHost.ToLower(); return String.Format("{0}_{1}", Name, hostname); } + + public override string GetQueryTitle(string title) + { + title = RemoveThe.Replace(title, string.Empty); + + //remove any repeating whitespace + var cleanTitle = TitleSearchRegex.Replace(title, "%20"); + + cleanTitle = Regex.Replace(cleanTitle, @"(%20){1,100}", "%20"); + + //Trim %20 from start then then the end + cleanTitle = Regex.Replace(cleanTitle, "^(%20)", ""); + cleanTitle = Regex.Replace(cleanTitle, "(%20)$", ""); + + return cleanTitle; + } } } \ No newline at end of file