From 4c4073ce1c48874b3b6c3d22211d254a3f71522a Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 29 Oct 2023 14:19:47 -0700 Subject: [PATCH] New: Support SABnzb's new format for sorters (cherry picked from commit d484553b310af4257c841c37a503ef54650c1426) Closes #9351 --- .../SabnzbdTests/SabnzbdFixture.cs | 46 +++++++++++++++++++ .../Download/Clients/Sabnzbd/Sabnzbd.cs | 10 ++++ .../Clients/Sabnzbd/SabnzbdCategory.cs | 20 ++++++++ 3 files changed, 76 insertions(+) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index fef51ec5d..eb0138188 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -543,6 +543,52 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests result.HasWarnings.Should().BeTrue(); } + [Test] + public void should_test_success_if_sorters_are_empty() + { + _config.Misc.enable_tv_sorting = false; + _config.Misc.tv_categories = null; + _config.Sorters = new List(); + + var result = new NzbDroneValidationResult(Subject.Test()); + + result.IsValid.Should().BeTrue(); + } + + [Test] + public void should_test_failed_if_sorter_is_enabled_for_non_tv_category() + { + _config.Misc.enable_tv_sorting = false; + _config.Misc.tv_categories = null; + _config.Sorters = Builder.CreateListOfSize(1) + .All() + .With(s => s.is_active = true) + .With(s => s.sort_cats = new List { "movie-custom" }) + .Build() + .ToList(); + + var result = new NzbDroneValidationResult(Subject.Test()); + + result.IsValid.Should().BeTrue(); + } + + [Test] + public void should_test_failed_if_sorter_is_enabled_for_tv_category() + { + _config.Misc.enable_tv_sorting = false; + _config.Misc.tv_categories = null; + _config.Sorters = Builder.CreateListOfSize(1) + .All() + .With(s => s.is_active = true) + .With(s => s.sort_cats = new List { "movie" }) + .Build() + .ToList(); + + var result = new NzbDroneValidationResult(Subject.Test()); + + result.IsValid.Should().BeFalse(); + } + [Test] public void should_test_success_if_tv_sorting_disabled() { diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 892cfbac4..85e41d965 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -482,6 +482,16 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd } } + // New in SABnzbd 4.1, but on older versions this will be empty and not apply + if (config.Sorters.Any(s => s.is_active && ContainsCategory(s.sort_cats, Settings.MovieCategory))) + { + return new NzbDroneValidationFailure("MovieCategory", "Disable TV Sorting") + { + InfoLink = _proxy.GetBaseUrl(Settings, "config/sorting/"), + DetailedDescription = "You must disable sorting for the category Radarr uses to prevent import issues. Go to Sabnzbd to fix it." + }; + } + if (config.Misc.enable_tv_sorting && ContainsCategory(config.Misc.tv_categories, Settings.MovieCategory)) { return new NzbDroneValidationFailure("MovieCategory", "Disable TV Sorting") diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdCategory.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdCategory.cs index 189b08257..aa04edc5d 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdCategory.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdCategory.cs @@ -11,11 +11,13 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd { Categories = new List(); Servers = new List(); + Sorters = new List(); } public SabnzbdConfigMisc Misc { get; set; } public List Categories { get; set; } public List Servers { get; set; } + public List Sorters { get; set; } } public class SabnzbdConfigMisc @@ -42,4 +44,22 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd public OsPath FullPath { get; set; } } + + public class SabnzbdSorter + { + public SabnzbdSorter() + { + sort_cats = new List(); + sort_type = new List(); + } + + public string name { get; set; } + public int order { get; set; } + public string min_size { get; set; } + public string multipart_label { get; set; } + public string sort_string { get; set; } + public List sort_cats { get; set; } + public List sort_type { get; set; } + public bool is_active { get; set; } + } }