From 34a09af01e1e13cb65e37179b29d4916726facd2 Mon Sep 17 00:00:00 2001 From: Qstick Date: Fri, 3 Sep 2021 14:50:03 -0400 Subject: [PATCH] New: Advanced settings for Application category control --- .../Components/Form/ProviderFieldFormGroup.js | 3 +- src/NzbDrone.Core/Annotations/SelectOption.cs | 1 + .../Applications/Lidarr/LidarrSettings.cs | 6 ++- .../Applications/Mylar/MylarSettings.cs | 6 ++- .../Applications/Radarr/RadarrSettings.cs | 7 +++- .../Applications/Readarr/ReadarrSettings.cs | 7 +++- .../Applications/Sonarr/SonarrSettings.cs | 10 +++-- .../Indexers/NewznabCategoryFieldConverter.cs | 40 +++++++++++++++++++ 8 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/NzbDrone.Core/Indexers/NewznabCategoryFieldConverter.cs diff --git a/frontend/src/Components/Form/ProviderFieldFormGroup.js b/frontend/src/Components/Form/ProviderFieldFormGroup.js index 3a9a2f5a5..89b54369b 100644 --- a/frontend/src/Components/Form/ProviderFieldFormGroup.js +++ b/frontend/src/Components/Form/ProviderFieldFormGroup.js @@ -53,7 +53,8 @@ function getSelectValues(selectOptions) { result.push({ key: option.value, value: option.name, - hint: option.hint + hint: option.hint, + parentKey: option.parentValue }); return result; diff --git a/src/NzbDrone.Core/Annotations/SelectOption.cs b/src/NzbDrone.Core/Annotations/SelectOption.cs index feef0c342..0460c86e8 100644 --- a/src/NzbDrone.Core/Annotations/SelectOption.cs +++ b/src/NzbDrone.Core/Annotations/SelectOption.cs @@ -6,5 +6,6 @@ namespace NzbDrone.Core.Annotations public string Name { get; set; } public int Order { get; set; } public string Hint { get; set; } + public int? ParentValue { get; set; } } } diff --git a/src/NzbDrone.Core/Applications/Lidarr/LidarrSettings.cs b/src/NzbDrone.Core/Applications/Lidarr/LidarrSettings.cs index c73df32ab..d1b341529 100644 --- a/src/NzbDrone.Core/Applications/Lidarr/LidarrSettings.cs +++ b/src/NzbDrone.Core/Applications/Lidarr/LidarrSettings.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; +using NzbDrone.Core.Indexers; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Applications.Lidarr @@ -26,8 +27,6 @@ namespace NzbDrone.Core.Applications.Lidarr SyncCategories = new[] { 3000, 3010, 3030, 3040, 3050, 3060 }; } - public IEnumerable SyncCategories { get; set; } - [FieldDefinition(0, Label = "Prowlarr Server", HelpText = "Prowlarr server URL as Lidarr sees it, including http(s)://, port, and urlbase if needed")] public string ProwlarrUrl { get; set; } @@ -37,6 +36,9 @@ namespace NzbDrone.Core.Applications.Lidarr [FieldDefinition(2, Label = "ApiKey", Privacy = PrivacyLevel.ApiKey, HelpText = "The ApiKey generated by Lidarr in Settings/General")] public string ApiKey { get; set; } + [FieldDefinition(3, Label = "Sync Categories", Type = FieldType.Select, SelectOptions = typeof(NewznabCategoryFieldConverter), Advanced = true, HelpText = "Only Indexers that support these categories will be synced")] + public IEnumerable SyncCategories { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/Applications/Mylar/MylarSettings.cs b/src/NzbDrone.Core/Applications/Mylar/MylarSettings.cs index 250316528..1b2c38c36 100644 --- a/src/NzbDrone.Core/Applications/Mylar/MylarSettings.cs +++ b/src/NzbDrone.Core/Applications/Mylar/MylarSettings.cs @@ -13,6 +13,7 @@ namespace NzbDrone.Core.Applications.Mylar RuleFor(c => c.BaseUrl).IsValidUrl(); RuleFor(c => c.ProwlarrUrl).IsValidUrl(); RuleFor(c => c.ApiKey).NotEmpty(); + RuleFor(c => c.SyncCategories).NotEmpty(); } } @@ -27,8 +28,6 @@ namespace NzbDrone.Core.Applications.Mylar SyncCategories = new[] { NewznabStandardCategory.BooksComics.Id }; } - public IEnumerable SyncCategories { get; set; } - [FieldDefinition(0, Label = "Prowlarr Server", HelpText = "Prowlarr server URL as Mylar sees it, including http(s)://, port, and urlbase if needed")] public string ProwlarrUrl { get; set; } @@ -38,6 +37,9 @@ namespace NzbDrone.Core.Applications.Mylar [FieldDefinition(2, Label = "ApiKey", Privacy = PrivacyLevel.ApiKey, HelpText = "The ApiKey generated by Mylar in Settings/Web Interface")] public string ApiKey { get; set; } + [FieldDefinition(3, Label = "Sync Categories", Type = FieldType.Select, SelectOptions = typeof(NewznabCategoryFieldConverter), Advanced = true, HelpText = "Only Indexers that support these categories will be synced")] + public IEnumerable SyncCategories { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/Applications/Radarr/RadarrSettings.cs b/src/NzbDrone.Core/Applications/Radarr/RadarrSettings.cs index 9e7d25946..08e9f6a69 100644 --- a/src/NzbDrone.Core/Applications/Radarr/RadarrSettings.cs +++ b/src/NzbDrone.Core/Applications/Radarr/RadarrSettings.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; +using NzbDrone.Core.Indexers; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Applications.Radarr @@ -12,6 +13,7 @@ namespace NzbDrone.Core.Applications.Radarr RuleFor(c => c.BaseUrl).IsValidUrl(); RuleFor(c => c.ProwlarrUrl).IsValidUrl(); RuleFor(c => c.ApiKey).NotEmpty(); + RuleFor(c => c.SyncCategories).NotEmpty(); } } @@ -26,8 +28,6 @@ namespace NzbDrone.Core.Applications.Radarr SyncCategories = new[] { 2000, 2010, 2020, 2030, 2040, 2045, 2050, 2060, 2070, 2080 }; } - public IEnumerable SyncCategories { get; set; } - [FieldDefinition(0, Label = "Prowlarr Server", HelpText = "Prowlarr server URL as Radarr sees it, including http(s)://, port, and urlbase if needed")] public string ProwlarrUrl { get; set; } @@ -37,6 +37,9 @@ namespace NzbDrone.Core.Applications.Radarr [FieldDefinition(2, Label = "ApiKey", Privacy = PrivacyLevel.ApiKey, HelpText = "The ApiKey generated by Radarr in Settings/General")] public string ApiKey { get; set; } + [FieldDefinition(3, Label = "Sync Categories", Type = FieldType.Select, SelectOptions = typeof(NewznabCategoryFieldConverter), Advanced = true, HelpText = "Only Indexers that support these categories will be synced")] + public IEnumerable SyncCategories { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/Applications/Readarr/ReadarrSettings.cs b/src/NzbDrone.Core/Applications/Readarr/ReadarrSettings.cs index c159ea0ad..7c97fa0d6 100644 --- a/src/NzbDrone.Core/Applications/Readarr/ReadarrSettings.cs +++ b/src/NzbDrone.Core/Applications/Readarr/ReadarrSettings.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; +using NzbDrone.Core.Indexers; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Applications.Readarr @@ -12,6 +13,7 @@ namespace NzbDrone.Core.Applications.Readarr RuleFor(c => c.BaseUrl).IsValidUrl(); RuleFor(c => c.ProwlarrUrl).IsValidUrl(); RuleFor(c => c.ApiKey).NotEmpty(); + RuleFor(c => c.SyncCategories).NotEmpty(); } } @@ -26,8 +28,6 @@ namespace NzbDrone.Core.Applications.Readarr SyncCategories = new[] { 3030, 7000, 7010, 7020, 7030, 7040, 7050, 7060 }; } - public IEnumerable SyncCategories { get; set; } - [FieldDefinition(0, Label = "Prowlarr Server", HelpText = "Prowlarr server URL as Readarr sees it, including http(s)://, port, and urlbase if needed")] public string ProwlarrUrl { get; set; } @@ -37,6 +37,9 @@ namespace NzbDrone.Core.Applications.Readarr [FieldDefinition(2, Label = "ApiKey", Privacy = PrivacyLevel.ApiKey, HelpText = "The ApiKey generated by Readarr in Settings/General")] public string ApiKey { get; set; } + [FieldDefinition(3, Label = "Sync Categories", Type = FieldType.Select, SelectOptions = typeof(NewznabCategoryFieldConverter), Advanced = true, HelpText = "Only Indexers that support these categories will be synced")] + public IEnumerable SyncCategories { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/Applications/Sonarr/SonarrSettings.cs b/src/NzbDrone.Core/Applications/Sonarr/SonarrSettings.cs index 0ab030ca4..26c2b90df 100644 --- a/src/NzbDrone.Core/Applications/Sonarr/SonarrSettings.cs +++ b/src/NzbDrone.Core/Applications/Sonarr/SonarrSettings.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; +using NzbDrone.Core.Indexers; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Applications.Sonarr @@ -27,9 +28,6 @@ namespace NzbDrone.Core.Applications.Sonarr AnimeSyncCategories = new[] { 5070 }; } - public IEnumerable SyncCategories { get; set; } - public IEnumerable AnimeSyncCategories { get; set; } - [FieldDefinition(0, Label = "Prowlarr Server", HelpText = "Prowlarr server URL as Sonarr sees it, including http(s)://, port, and urlbase if needed")] public string ProwlarrUrl { get; set; } @@ -39,6 +37,12 @@ namespace NzbDrone.Core.Applications.Sonarr [FieldDefinition(2, Label = "ApiKey", Privacy = PrivacyLevel.ApiKey, HelpText = "The ApiKey generated by Sonarr in Settings/General")] public string ApiKey { get; set; } + [FieldDefinition(3, Label = "Sync Categories", Type = FieldType.Select, SelectOptions = typeof(NewznabCategoryFieldConverter), Advanced = true, HelpText = "Only Indexers that support these categories will be synced")] + public IEnumerable SyncCategories { get; set; } + + [FieldDefinition(4, Label = "Anime Sync Categories", Type = FieldType.Select, SelectOptions = typeof(NewznabCategoryFieldConverter), Advanced = true, HelpText = "Only Indexers that support these categories will be synced")] + public IEnumerable AnimeSyncCategories { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/Indexers/NewznabCategoryFieldConverter.cs b/src/NzbDrone.Core/Indexers/NewznabCategoryFieldConverter.cs new file mode 100644 index 000000000..b6484d908 --- /dev/null +++ b/src/NzbDrone.Core/Indexers/NewznabCategoryFieldConverter.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using NzbDrone.Core.Annotations; + +namespace NzbDrone.Core.Indexers +{ + public class NewznabCategoryFieldConverter : ISelectOptionsConverter + { + public List GetSelectOptions() + { + var result = new List(); + + foreach (var category in NewznabStandardCategory.ParentCats) + { + result.Add(new SelectOption + { + Value = category.Id, + Name = category.Name, + Hint = $"({category.Id})" + }); + + if (category.SubCategories != null) + { + foreach (var subcat in category.SubCategories.OrderBy(cat => cat.Id)) + { + result.Add(new SelectOption + { + Value = subcat.Id, + Name = subcat.Name, + Hint = $"({subcat.Id})", + ParentValue = category.Id + }); + } + } + } + + return result; + } + } +}