From 1cbcad6960c035603e1dc3cf8ddb0c487a29969d Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Mon, 25 Jan 2021 21:33:59 +0100 Subject: [PATCH] Added searchEngine support in Newznab/Torznab caps --- .../NewznabCapabilitiesProviderFixture.cs | 23 ++++++++++++++++ .../Indexers/Newznab/NewznabCapabilities.cs | 4 +++ .../Newznab/NewznabCapabilitiesProvider.cs | 18 +++++++++---- .../Newznab/NewznabRequestGenerator.cs | 26 +++++++++++++++++-- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs index f75ceab36..3037c4f17 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs @@ -97,5 +97,28 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests ExceptionVerification.ExpectedErrors(1); } + + [Test] + public void should_use_default_searchengine_if_missing() + { + GivenCapsResponse(_caps); + + var caps = Subject.GetCapabilities(_settings); + + caps.TextSearchEngine.Should().Be("sphinx"); + caps.TvTextSearchEngine.Should().Be("sphinx"); + } + + [Test] + public void should_use_specified_searchengine() + { + GivenCapsResponse(_caps.Replace(" Categories { get; set; } public NewznabCapabilities() @@ -18,6 +20,8 @@ namespace NzbDrone.Core.Indexers.Newznab SupportedSearchParameters = new[] { "q" }; SupportedTvSearchParameters = new[] { "q", "rid", "season", "ep" }; // This should remain 'rid' for older newznab installs. SupportsAggregateIdSearch = false; + TextSearchEngine = "sphinx"; // This should remain 'sphinx' for odler newznab installs + TvTextSearchEngine = "sphinx"; // This should remain 'sphinx' for odler newznab installs Categories = new List(); } } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs index 457f3ef29..31f959412 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs @@ -120,9 +120,13 @@ namespace NzbDrone.Core.Indexers.Newznab { capabilities.SupportedSearchParameters = null; } - else if (xmlBasicSearch.Attribute("supportedParams") != null) + else { - capabilities.SupportedSearchParameters = xmlBasicSearch.Attribute("supportedParams").Value.Split(','); + if (xmlBasicSearch.Attribute("supportedParams") != null) + { + capabilities.SupportedSearchParameters = xmlBasicSearch.Attribute("supportedParams").Value.Split(','); + } + capabilities.TextSearchEngine = xmlBasicSearch.Attribute("searchEngine")?.Value ?? capabilities.TextSearchEngine; } var xmlTvSearch = xmlSearching.Element("tv-search"); @@ -130,10 +134,14 @@ namespace NzbDrone.Core.Indexers.Newznab { capabilities.SupportedTvSearchParameters = null; } - else if (xmlTvSearch.Attribute("supportedParams") != null) + else { - capabilities.SupportedTvSearchParameters = xmlTvSearch.Attribute("supportedParams").Value.Split(','); - capabilities.SupportsAggregateIdSearch = true; + if (xmlTvSearch.Attribute("supportedParams") != null) + { + capabilities.SupportedTvSearchParameters = xmlTvSearch.Attribute("supportedParams").Value.Split(','); + capabilities.SupportsAggregateIdSearch = true; + } + capabilities.TvTextSearchEngine = xmlTvSearch.Attribute("searchEngine")?.Value ?? capabilities.TvTextSearchEngine; } } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs index 5c512d0b8..8bbeba28f 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs @@ -121,6 +121,26 @@ namespace NzbDrone.Core.Indexers.Newznab } } + private string TextSearchEngine + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.TextSearchEngine; + } + } + + private string TvTextSearchEngine + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.TvTextSearchEngine; + } + } + public virtual IndexerPageableRequestChain GetRecentRequests() { var pageableRequests = new IndexerPageableRequestChain(); @@ -269,7 +289,8 @@ namespace NzbDrone.Core.Indexers.Newznab if (SupportsSearch) { - foreach (var queryTitle in searchCriteria.QueryTitles) + var queryTitles = (TextSearchEngine == "raw" ? searchCriteria.SceneTitles : searchCriteria.QueryTitles); + foreach (var queryTitle in queryTitles) { pageableRequests.Add(GetPagedRequests(MaxPages, Settings.AnimeCategories, "search", string.Format("&q={0}+{1:00}", @@ -373,7 +394,8 @@ namespace NzbDrone.Core.Indexers.Newznab } else if (SupportsTvSearch) { - foreach (var queryTitle in searchCriteria.QueryTitles) + var queryTitles = TvTextSearchEngine == "raw" ? searchCriteria.SceneTitles : searchCriteria.QueryTitles; + foreach (var queryTitle in queryTitles) { chain.Add(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", string.Format("&q={0}{1}",