Added searchEngine support in Newznab/Torznab caps

Fixes #5849

Co-Authored-By: Taloth <Taloth@users.noreply.github.com>
pull/6437/head
Qstick 3 years ago
parent 143067621c
commit eb76dd5248

@ -1,4 +1,4 @@
using System;
using System;
using System.Xml;
using FluentAssertions;
using Moq;
@ -95,5 +95,28 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
result.Should().NotBeNull();
}
[Test]
public void should_use_default_searchengine_if_missing()
{
GivenCapsResponse(_caps);
var caps = Subject.GetCapabilities(_settings);
caps.TextSearchEngine.Should().Be("sphinx");
caps.MovieTextSearchEngine.Should().Be("sphinx");
}
[Test]
public void should_use_specified_searchengine()
{
GivenCapsResponse(_caps.Replace("<search ", "<search searchEngine=\"raw\" ")
.Replace("<movie-search ", "<movie-search searchEngine=\"raw2\" "));
var caps = Subject.GetCapabilities(_settings);
caps.TextSearchEngine.Should().Be("raw");
caps.MovieTextSearchEngine.Should().Be("raw2");
}
}
}

@ -9,6 +9,8 @@ namespace NzbDrone.Core.Indexers.Newznab
public string[] SupportedSearchParameters { get; set; }
public string[] SupportedMovieSearchParameters { get; set; }
public bool SupportsAggregateIdSearch { get; set; }
public string TextSearchEngine { get; set; }
public string MovieTextSearchEngine { get; set; }
public List<NewznabCategory> Categories { get; set; }
public NewznabCapabilities()
@ -18,6 +20,8 @@ namespace NzbDrone.Core.Indexers.Newznab
SupportedSearchParameters = new[] { "q" };
SupportedMovieSearchParameters = new[] { "q", "imdbid", "imdbtitle", "imdbyear" };
SupportsAggregateIdSearch = false;
TextSearchEngine = "sphinx"; // This should remain 'sphinx' for older newznab installs
MovieTextSearchEngine = "sphinx"; // This should remain 'sphinx' for older newznab installs
Categories = new List<NewznabCategory>();
}
}

@ -118,9 +118,14 @@ 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 xmlMovieSearch = xmlSearching.Element("movie-search");
@ -128,10 +133,15 @@ namespace NzbDrone.Core.Indexers.Newznab
{
capabilities.SupportedMovieSearchParameters = null;
}
else if (xmlMovieSearch.Attribute("supportedParams") != null)
else
{
capabilities.SupportedMovieSearchParameters = xmlMovieSearch.Attribute("supportedParams").Value.Split(',');
capabilities.SupportsAggregateIdSearch = true;
if (xmlMovieSearch.Attribute("supportedParams") != null)
{
capabilities.SupportedMovieSearchParameters = xmlMovieSearch.Attribute("supportedParams").Value.Split(',');
capabilities.SupportsAggregateIdSearch = true;
}
capabilities.MovieTextSearchEngine = xmlMovieSearch.Attribute("searchEngine")?.Value ?? capabilities.MovieTextSearchEngine;
}
}

@ -65,6 +65,26 @@ namespace NzbDrone.Core.Indexers.Newznab
}
}
private string TextSearchEngine
{
get
{
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
return capabilities.TextSearchEngine;
}
}
private string MovieTextSearchEngine
{
get
{
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
return capabilities.MovieTextSearchEngine;
}
}
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new IndexerPageableRequestChain();
@ -135,7 +155,8 @@ namespace NzbDrone.Core.Indexers.Newznab
if (SupportsSearch)
{
chain.AddTier();
foreach (var queryTitle in searchCriteria.QueryTitles)
var queryTitles = TextSearchEngine == "raw" ? searchCriteria.SceneTitles : searchCriteria.QueryTitles;
foreach (var queryTitle in queryTitles)
{
var searchQuery = queryTitle;

Loading…
Cancel
Save