From 4dac60bef9063f4a3ff9d77b1ee1cdeb944cf557 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 1 Apr 2024 00:49:31 +0300 Subject: [PATCH] Fixed: Displaying capabilities for Newznab and Torznab feeds (#2083) --- .../Indexers/Definitions/Newznab/Newznab.cs | 18 +++++++--- .../Newznab/NewznabCapabilitiesProvider.cs | 10 +++--- .../Newznab/NewznabCapabilitiesSettings.cs | 35 +++++++++++++++++++ .../Definitions/Newznab/NewznabSettings.cs | 3 +- .../Indexers/Definitions/Torznab/Torznab.cs | 18 +++++++--- src/NzbDrone.Core/Indexers/IndexerFactory.cs | 8 +++-- 6 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesSettings.cs diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/Newznab.cs index 882cb6e5e..e7109f504 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/Newznab.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/Newznab.cs @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Indexers.Newznab public string[] GetBaseUrlFromSettings() { - if (Definition == null || Settings?.Categories == null) + if (Definition == null || Settings?.Capabilities == null) { return new[] { "" }; } @@ -61,14 +61,24 @@ namespace NzbDrone.Core.Indexers.Newznab { var caps = new IndexerCapabilities(); - if (Definition == null || Settings?.Categories == null) + if (Definition == null || Settings?.Capabilities == null) { return caps; } - foreach (var category in Settings.Categories) + caps.SupportsRawSearch = Settings.Capabilities?.SupportsRawSearch ?? false; + caps.SearchParams = Settings.Capabilities?.SearchParams ?? new List { SearchParam.Q }; + caps.TvSearchParams = Settings.Capabilities?.TvSearchParams ?? new List(); + caps.MovieSearchParams = Settings.Capabilities?.MovieSearchParams ?? new List(); + caps.MusicSearchParams = Settings.Capabilities?.MusicSearchParams ?? new List(); + caps.BookSearchParams = Settings.Capabilities?.BookSearchParams ?? new List(); + + if (Settings.Capabilities?.Categories != null) { - caps.Categories.AddCategoryMapping(category.Name, category); + foreach (var category in Settings.Capabilities.Categories) + { + caps.Categories.AddCategoryMapping(category.Name, category); + } } return caps; diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesProvider.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesProvider.cs index e182b97e7..f72f0a9f9 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesProvider.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesProvider.cs @@ -124,7 +124,7 @@ namespace NzbDrone.Core.Indexers.Newznab { foreach (var param in xmlBasicSearch.Attribute("supportedParams").Value.Split(',')) { - if (Enum.TryParse(param, true, out SearchParam searchParam)) + if (Enum.TryParse(param, true, out SearchParam searchParam) && !capabilities.SearchParams.Contains(searchParam)) { capabilities.SearchParams.AddIfNotNull(searchParam); } @@ -146,7 +146,7 @@ namespace NzbDrone.Core.Indexers.Newznab { foreach (var param in xmlMovieSearch.Attribute("supportedParams").Value.Split(',')) { - if (Enum.TryParse(param, true, out MovieSearchParam searchParam)) + if (Enum.TryParse(param, true, out MovieSearchParam searchParam) && !capabilities.MovieSearchParams.Contains(searchParam)) { capabilities.MovieSearchParams.AddIfNotNull(searchParam); } @@ -166,7 +166,7 @@ namespace NzbDrone.Core.Indexers.Newznab { foreach (var param in xmlTvSearch.Attribute("supportedParams").Value.Split(',')) { - if (Enum.TryParse(param, true, out TvSearchParam searchParam)) + if (Enum.TryParse(param, true, out TvSearchParam searchParam) && !capabilities.TvSearchParams.Contains(searchParam)) { capabilities.TvSearchParams.AddIfNotNull(searchParam); } @@ -186,7 +186,7 @@ namespace NzbDrone.Core.Indexers.Newznab { foreach (var param in xmlAudioSearch.Attribute("supportedParams").Value.Split(',')) { - if (Enum.TryParse(param, true, out MusicSearchParam searchParam)) + if (Enum.TryParse(param, true, out MusicSearchParam searchParam) && !capabilities.MusicSearchParams.Contains(searchParam)) { capabilities.MusicSearchParams.AddIfNotNull(searchParam); } @@ -206,7 +206,7 @@ namespace NzbDrone.Core.Indexers.Newznab { foreach (var param in xmlBookSearch.Attribute("supportedParams").Value.Split(',')) { - if (Enum.TryParse(param, true, out BookSearchParam searchParam)) + if (Enum.TryParse(param, true, out BookSearchParam searchParam) && !capabilities.BookSearchParams.Contains(searchParam)) { capabilities.BookSearchParams.AddIfNotNull(searchParam); } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesSettings.cs new file mode 100644 index 000000000..244d1c869 --- /dev/null +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesSettings.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; + +namespace NzbDrone.Core.Indexers.Newznab; + +public class NewznabCapabilitiesSettings +{ + public bool SupportsRawSearch { get; set; } + + public List SearchParams { get; set; } = new (); + + public List TvSearchParams { get; set; } = new (); + + public List MovieSearchParams { get; set; } = new (); + + public List MusicSearchParams { get; set; } = new (); + + public List BookSearchParams { get; set; } = new (); + + public List Categories { get; set; } = new (); + + public NewznabCapabilitiesSettings() + { + } + + public NewznabCapabilitiesSettings(IndexerCapabilities capabilities) + { + SupportsRawSearch = capabilities?.SupportsRawSearch ?? false; + SearchParams = capabilities?.SearchParams; + TvSearchParams = capabilities?.TvSearchParams; + MovieSearchParams = capabilities?.MovieSearchParams; + MusicSearchParams = capabilities?.MusicSearchParams; + BookSearchParams = capabilities?.BookSearchParams; + Categories = capabilities?.Categories.GetTorznabCategoryList(); + } +} diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs index b517c5894..67b787e12 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using FluentValidation; @@ -76,7 +75,7 @@ namespace NzbDrone.Core.Indexers.Newznab [FieldDefinition(7)] public IndexerBaseSettings BaseSettings { get; set; } = new (); - public List Categories { get; set; } + public NewznabCapabilitiesSettings Capabilities { get; set; } // Field 8 is used by TorznabSettings MinimumSeeders // If you need to add another field here, update TorznabSettings as well and this comment diff --git a/src/NzbDrone.Core/Indexers/Definitions/Torznab/Torznab.cs b/src/NzbDrone.Core/Indexers/Definitions/Torznab/Torznab.cs index 512aaf091..049fec0b1 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Torznab/Torznab.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Torznab/Torznab.cs @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Indexers.Torznab public string[] GetBaseUrlFromSettings() { - if (Definition == null || Settings?.Categories == null) + if (Definition == null || Settings?.Capabilities == null) { return new[] { "" }; } @@ -61,14 +61,24 @@ namespace NzbDrone.Core.Indexers.Torznab { var caps = new IndexerCapabilities(); - if (Definition == null || Settings?.Categories == null) + if (Definition == null || Settings?.Capabilities == null) { return caps; } - foreach (var category in Settings.Categories) + caps.SupportsRawSearch = Settings.Capabilities?.SupportsRawSearch ?? false; + caps.SearchParams = Settings.Capabilities?.SearchParams ?? new List { SearchParam.Q }; + caps.TvSearchParams = Settings.Capabilities?.TvSearchParams ?? new List(); + caps.MovieSearchParams = Settings.Capabilities?.MovieSearchParams ?? new List(); + caps.MusicSearchParams = Settings.Capabilities?.MusicSearchParams ?? new List(); + caps.BookSearchParams = Settings.Capabilities?.BookSearchParams ?? new List(); + + if (Settings.Capabilities?.Categories != null) { - caps.Categories.AddCategoryMapping(category.Name, category); + foreach (var category in Settings.Capabilities.Categories) + { + caps.Categories.AddCategoryMapping(category.Name, category); + } } return caps; diff --git a/src/NzbDrone.Core/Indexers/IndexerFactory.cs b/src/NzbDrone.Core/Indexers/IndexerFactory.cs index a5f4e6601..0c9668fab 100644 --- a/src/NzbDrone.Core/Indexers/IndexerFactory.cs +++ b/src/NzbDrone.Core/Indexers/IndexerFactory.cs @@ -284,7 +284,9 @@ namespace NzbDrone.Core.Indexers if (definition.Enable && definition.Implementation is nameof(Newznab.Newznab) or nameof(Torznab.Torznab)) { var settings = (NewznabSettings)definition.Settings; - settings.Categories = _newznabCapabilitiesProvider.GetCapabilities(settings, definition)?.Categories.GetTorznabCategoryList(); + var capabilities = _newznabCapabilitiesProvider.GetCapabilities(settings, definition); + + settings.Capabilities = new NewznabCapabilitiesSettings(capabilities); } if (definition.Implementation == nameof(Cardigann)) @@ -304,7 +306,9 @@ namespace NzbDrone.Core.Indexers if (definition.Enable && definition.Implementation is nameof(Newznab.Newznab) or nameof(Torznab.Torznab)) { var settings = (NewznabSettings)definition.Settings; - settings.Categories = _newznabCapabilitiesProvider.GetCapabilities(settings, definition)?.Categories.GetTorznabCategoryList(); + var capabilities = _newznabCapabilitiesProvider.GetCapabilities(settings, definition); + + settings.Capabilities = new NewznabCapabilitiesSettings(capabilities); } if (definition.Implementation == nameof(Cardigann))