From d484553b310af4257c841c37a503ef54650c1426 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 Closes #6125 --- .../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 a0c8b656b..b81633b51 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 { "tv-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 { "tv" }) + .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 00bcf5cac..95f8942aa 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.TvCategory))) + { + return new NzbDroneValidationFailure("TvCategory", "Disable TV Sorting") + { + InfoLink = _proxy.GetBaseUrl(Settings, "config/sorting/"), + DetailedDescription = "You must disable sorting for the category Sonarr uses to prevent import issues. Go to Sabnzbd to fix it." + }; + } + if (config.Misc.enable_tv_sorting && ContainsCategory(config.Misc.tv_categories, Settings.TvCategory)) { return new NzbDroneValidationFailure("TvCategory", "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; } + } }