From 308fd11c838aa267b6cc3d5a9a58fea23b522c91 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 11 Feb 2012 00:09:28 -0800 Subject: [PATCH] Fix: Series Titles with apostrophes when searched on NzbMatrix will now return valid results. Each indexer can now override GetQueryTitle from IndexerBase if required for special title searching. --- NzbDrone.Core.Test/IndexerTests.cs | 14 +++++++++++++- NzbDrone.Core/Providers/Indexer/IndexerBase.cs | 7 ++++++- NzbDrone.Core/Providers/Indexer/NzbMatrix.cs | 14 +++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/NzbDrone.Core.Test/IndexerTests.cs b/NzbDrone.Core.Test/IndexerTests.cs index 045eced0e..d80625690 100644 --- a/NzbDrone.Core.Test/IndexerTests.cs +++ b/NzbDrone.Core.Test/IndexerTests.cs @@ -270,10 +270,22 @@ public void nzbmatrix_multi_word_search_returns_valid_results() [TestCase("hawaii five-0 (2010)", "hawaii+five+0+2010")] [TestCase("this& that", "this+that")] [TestCase("this& that", "this+that")] + [TestCase("grey's anatomy", "grey+s+anatomy")] public void get_query_title(string raw, string clean) { - var result = IndexerBase.GetQueryTitle(raw); + var mock = new Mock(); + mock.CallBase = true; + var result = mock.Object.GetQueryTitle(raw); + result.Should().Be(clean); + } + [TestCase("hawaii five-0 (2010)", "hawaii+five+0+2010")] + [TestCase("this& that", "this+that")] + [TestCase("this& that", "this+that")] + [TestCase("grey's anatomy", "greys+anatomy")] + public void get_query_title_nzbmatrix_should_replace_apostrophe_with_empty_string(string raw, string clean) + { + var result = Mocker.Resolve().GetQueryTitle(raw); result.Should().Be(clean); } diff --git a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs index 81b880183..affcee148 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs @@ -222,7 +222,12 @@ public EpisodeParseResult ParseFeed(SyndicationItem item) return CustomParser(item, episodeParseResult); } - public static string GetQueryTitle(string title) + /// + /// This method can be overwritten to provide indexer specific title cleaning + /// + /// Title that needs to be cleaned + /// + public virtual string GetQueryTitle(string title) { var cleanTitle = TitleSearchRegex.Replace(title, "+").Trim('+', ' '); diff --git a/NzbDrone.Core/Providers/Indexer/NzbMatrix.cs b/NzbDrone.Core/Providers/Indexer/NzbMatrix.cs index 2e10c84bf..89b758566 100644 --- a/NzbDrone.Core/Providers/Indexer/NzbMatrix.cs +++ b/NzbDrone.Core/Providers/Indexer/NzbMatrix.cs @@ -17,6 +17,8 @@ public NzbMatrix(HttpProvider httpProvider, ConfigProvider configProvider) { } + private static readonly Regex TitleSearchRegex = new Regex(@"[\W]", RegexOptions.IgnoreCase | RegexOptions.Compiled); + protected override string[] Urls { get @@ -94,7 +96,6 @@ public override string Name get { return "NzbMatrix"; } } - protected override string NzbDownloadUrl(SyndicationItem item) { return item.Links[0].Uri.ToString(); @@ -110,5 +111,16 @@ protected override EpisodeParseResult CustomParser(SyndicationItem item, Episode } return currentResult; } + + public override string GetQueryTitle(string title) + { + //Replace apostrophe with empty string + title = title.Replace("'", ""); + var cleanTitle = TitleSearchRegex.Replace(title, "+").Trim('+', ' '); + + //remove any repeating +s + cleanTitle = Regex.Replace(cleanTitle, @"\+{1,100}", "+"); + return cleanTitle; + } } } \ No newline at end of file