From 949d8bf49b96f2e9225c45a024bcb630518e1579 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 25 Feb 2016 20:39:42 +0100 Subject: [PATCH] Fixed: Warn if user has movie/date sorting enabled in Sabnzbd for the Sonarr category. --- .../SabnzbdStringArrayConverter.cs | 48 +++++++++++++++++++ .../Download/Clients/Sabnzbd/Sabnzbd.cs | 28 +++++++++++ .../Clients/Sabnzbd/SabnzbdCategory.cs | 7 +++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 84 insertions(+) create mode 100644 src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdStringArrayConverter.cs diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdStringArrayConverter.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdStringArrayConverter.cs new file mode 100644 index 000000000..84a5a1bc9 --- /dev/null +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdStringArrayConverter.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace NzbDrone.Core.Download.Clients.Sabnzbd.JsonConverters +{ + /// + /// On some properties sab serializes array of single item as plain string. + /// + public class SabnzbdStringArrayConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var stringArray = (string[])value; + writer.WriteStartArray(); + + for (int i = 0; i < stringArray.Length; i++) + { + writer.WriteValue(stringArray[i]); + } + + writer.WriteEnd(); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.String || reader.TokenType == JsonToken.Null) + { + return new string[] { JValue.Load(reader).ToObject() }; + } + else if (reader.TokenType == JsonToken.StartArray) + { + return JArray.Load(reader).ToObject(); + } + else + { + throw new JsonReaderException("Expected array"); + } + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(string[]); + } + } +} diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 06054da8c..8632de04e 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -376,6 +376,34 @@ private ValidationFailure TestCategory() } } + if (config.Misc.enable_movie_sorting) + { + if (!config.Misc.movie_categories.Any() || + config.Misc.movie_categories.Contains(Settings.TvCategory) || + (Settings.TvCategory.IsNullOrWhiteSpace() && config.Misc.movie_categories.Contains("Default"))) + { + return new NzbDroneValidationFailure("TvCategory", "Disable Movie Sorting") + { + InfoLink = string.Format("http://{0}:{1}/sabnzbd/config/sorting/", Settings.Host, Settings.Port), + DetailedDescription = "You must disable Sabnzbd Movie Sorting for the category Sonarr uses to prevent import issues. Go to Sabnzbd to fix it." + }; + } + } + + if (config.Misc.enable_date_sorting) + { + if (!config.Misc.date_categories.Any() || + config.Misc.date_categories.Contains(Settings.TvCategory) || + (Settings.TvCategory.IsNullOrWhiteSpace() && config.Misc.date_categories.Contains("Default"))) + { + return new NzbDroneValidationFailure("TvCategory", "Disable Date Sorting") + { + InfoLink = string.Format("http://{0}:{1}/sabnzbd/config/sorting/", Settings.Host, Settings.Port), + DetailedDescription = "You must disable Sabnzbd Date Sorting for the category Sonarr uses to prevent import issues. Go to Sabnzbd to fix it." + }; + } + } + return null; } } diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdCategory.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdCategory.cs index d8885c567..08df67a74 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdCategory.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdCategory.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using Newtonsoft.Json; using NzbDrone.Common.Disk; +using NzbDrone.Core.Download.Clients.Sabnzbd.JsonConverters; namespace NzbDrone.Core.Download.Clients.Sabnzbd { @@ -18,6 +20,11 @@ public class SabnzbdConfigMisc public string complete_dir { get; set; } public string[] tv_categories { get; set; } public bool enable_tv_sorting { get; set; } + public string[] movie_categories { get; set; } + public bool enable_movie_sorting { get; set; } + [JsonConverter(typeof(SabnzbdStringArrayConverter))] + public string[] date_categories { get; set; } + public bool enable_date_sorting { get; set; } public bool pre_check { get; set; } } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 4a0eb35b5..d3640bc17 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -396,6 +396,7 @@ +