From d1c2569aa6c51fb3a36ebc612f41e9ba09bde32b Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Tue, 8 May 2018 22:19:36 +0200 Subject: [PATCH] Fixed: Indexers that do not support movie search should give better error messages. Radarr now also complains if an indexer does not support certain categories. --- src/.idea/.idea.NzbDrone/.idea/vcs.xml | 7 +++++ src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 21 +++++++++++++-- src/NzbDrone.Core/Indexers/Newznab/Newznab.cs | 23 ++++++++++++++-- .../Newznab/NewznabRequestGenerator.cs | 5 ++++ src/NzbDrone.Core/Indexers/Torznab/Torznab.cs | 27 +++++++++++++++++-- 5 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 src/.idea/.idea.NzbDrone/.idea/vcs.xml diff --git a/src/.idea/.idea.NzbDrone/.idea/vcs.xml b/src/.idea/.idea.NzbDrone/.idea/vcs.xml new file mode 100644 index 000000000..ea6ca8297 --- /dev/null +++ b/src/.idea/.idea.NzbDrone/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index d193dbea9..9251ffc6e 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -298,7 +298,8 @@ protected virtual ValidationFailure TestConnection() if (releases.Empty()) { - return new ValidationFailure(string.Empty, "No results were returned from your indexer, please check your settings."); + return new ValidationFailure(string.Empty, + "No results were returned from your indexer, please check your settings."); } } catch (ApiKeyException) @@ -319,7 +320,8 @@ protected virtual ValidationFailure TestConnection() } else { - return new ValidationFailure("CaptchaToken", "Site protected by CloudFlare CAPTCHA. Valid CAPTCHA token required."); + return new ValidationFailure("CaptchaToken", + "Site protected by CloudFlare CAPTCHA. Valid CAPTCHA token required."); } } catch (UnsupportedFeedException ex) @@ -334,6 +336,21 @@ protected virtual ValidationFailure TestConnection() return new ValidationFailure(string.Empty, "Unable to connect to indexer. " + ex.Message); } + catch (HttpException ex) + { + if (ex.Response.StatusCode == HttpStatusCode.BadRequest && + ex.Response.Content.Contains("not support the requested query")) + { + _logger.Warn(ex, "Indexer does not support the query"); + return new ValidationFailure(string.Empty, "Indexer does not support the current query. Check if the categories and or searching for movies are supported. Check the log for more details."); + } + else + { + _logger.Warn(ex, "Unable to connect to indexer"); + + return new ValidationFailure(string.Empty, "Unable to connect to indexer, check the log for more details"); + } + } catch (Exception ex) { _logger.Warn(ex, "Unable to connect to indexer"); diff --git a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs index f0ed6a7f8..573d51937 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -93,25 +93,44 @@ protected override void Test(List failures) failures.AddIfNotNull(TestCapabilities()); } + protected static List CategoryIds(List categories) + { + var l = categories.Select(c => c.Id).ToList(); + + foreach (var category in categories) + { + l.AddRange(CategoryIds(category.Subcategories)); + } + + return l; + } + protected virtual ValidationFailure TestCapabilities() { try { var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + var notSupported = Settings.Categories.Except(CategoryIds(capabilities.Categories)); + + if (notSupported.Any()) + { + return new ValidationFailure(string.Empty, $"This indexer does not support the following categories: {string.Join(", ", notSupported)}"); + } + if (capabilities.SupportedSearchParameters != null && capabilities.SupportedSearchParameters.Contains("q")) { return null; } - if (capabilities.SupportedTvSearchParameters != null && + if (capabilities.SupportedMovieSearchParameters != null && new[] { "q", "imdbid" }.Any(v => capabilities.SupportedMovieSearchParameters.Contains(v)) && new[] { "imdbtitle", "imdbyear" }.All(v => capabilities.SupportedMovieSearchParameters.Contains(v))) { return null; } - return new ValidationFailure(string.Empty, "Indexer does not support required search parameters"); + return new ValidationFailure(string.Empty, "This indexer does not support searching for movies :(. Tell your indexer staff to enable this or force add the indexer by disabling search, adding the indexer and then enabling it again."); } catch (Exception ex) { diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs index 2adbde4d7..b38929f98 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs @@ -40,10 +40,15 @@ public virtual IndexerPageableRequestChain GetRecentRequests() var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + // Some indexers might forget to enable movie search, but normal search still works fine. Thus we force a normal search. if (capabilities.SupportedMovieSearchParameters != null) { pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "movie", "")); } + else if (capabilities.SupportedSearchParameters != null) + { + pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "search", "")); + } return pageableRequests; } diff --git a/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs b/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs index 0678a12c2..32af77d47 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs @@ -83,24 +83,47 @@ protected override void Test(List failures) failures.AddIfNotNull(TestCapabilities()); } + protected static List CategoryIds(List categories) + { + var l = categories.Select(c => c.Id).ToList(); + + foreach (var category in categories) + { + if (category.Subcategories != null) + l.AddRange(CategoryIds(category.Subcategories)); + } + + return l; + } + protected virtual ValidationFailure TestCapabilities() { try { var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + var notSupported = Settings.Categories.Except(CategoryIds(capabilities.Categories)); + + if (notSupported.Any()) + { + _logger.Warn($"{Definition.Name} does not support the following categories: {string.Join(", ", notSupported)}"); + if (notSupported.Count() == Settings.Categories.Count()) + return new ValidationFailure(string.Empty, $"This indexer does not support any of the selected categories! (You may need to turn on advanced settings to see them)"); + } + if (capabilities.SupportedSearchParameters != null && capabilities.SupportedSearchParameters.Contains("q")) { return null; } if (capabilities.SupportedMovieSearchParameters != null && - new[] { "q", "imdbid" }.Any(v => capabilities.SupportedMovieSearchParameters.Contains(v))) + new[] { "q", "imdbid" }.Any(v => capabilities.SupportedMovieSearchParameters.Contains(v)) && + new[] { "imdbtitle", "imdbyear" }.All(v => capabilities.SupportedMovieSearchParameters.Contains(v))) { return null; } - return new ValidationFailure(string.Empty, "Indexer does not support required search parameters"); + return new ValidationFailure(string.Empty, "This indexer does not support searching for movies :(. Tell your indexer staff to enable this or force add the indexer by disabling search, adding the indexer and then enabling it again."); } catch (Exception ex) {