diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs index 9cbf3c4ca..7ae2d8a35 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs @@ -121,6 +121,13 @@ namespace NzbDrone.Core.Download.Clients.Deluge torrents = _proxy.GetTorrents(Settings); } + var useFailureCategory = Settings.MusicFailureCategory.IsNotNullOrWhiteSpace(); + + if (useFailureCategory) + { + torrents = torrents.Concat(_proxy.GetTorrentsByLabel(Settings.MusicFailureCategory, Settings)); + } + var items = new List(); foreach (var torrent in torrents) @@ -154,7 +161,11 @@ namespace NzbDrone.Core.Download.Clients.Deluge item.TotalSize = torrent.Size; - if (torrent.State == DelugeTorrentStatus.Error) + if (useFailureCategory && torrent.Label == Settings.MusicFailureCategory) + { + item.Status = DownloadItemStatus.Failed; + } + else if (torrent.State == DelugeTorrentStatus.Error) { item.Status = DownloadItemStatus.Warning; item.Message = "Deluge is reporting an error"; @@ -280,9 +291,9 @@ namespace NzbDrone.Core.Download.Clients.Deluge _logger.Error(ex, "Failed to test connection"); return new NzbDroneValidationFailure("Host", "Unable to connect to Deluge") - { - DetailedDescription = ex.Message - }; + { + DetailedDescription = ex.Message + }; } return null; @@ -335,6 +346,20 @@ namespace NzbDrone.Core.Download.Clients.Deluge } } + if (Settings.MusicFailureCategory.IsNotNullOrWhiteSpace() && !labels.Contains(Settings.MusicFailureCategory)) + { + _proxy.AddLabel(Settings.MusicFailureCategory, Settings); + labels = _proxy.GetAvailableLabels(Settings); + + if (!labels.Contains(Settings.MusicFailureCategory)) + { + return new NzbDroneValidationFailure("MusicFailureCategory", "Configuration of label failed") + { + DetailedDescription = "Lidarr was unable to add the label to Deluge." + }; + } + } + return null; } diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs index e6071fb53..309d10889 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs @@ -34,7 +34,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge public class DelugeProxy : IDelugeProxy { - private static readonly string[] RequiredProperties = new string[] { "hash", "name", "state", "progress", "eta", "message", "is_finished", "save_path", "total_size", "total_done", "time_added", "active_time", "ratio", "is_auto_managed", "stop_at_ratio", "remove_at_ratio", "stop_ratio" }; + private static readonly string[] RequiredProperties = new string[] { "hash", "name", "state", "progress", "eta", "message", "is_finished", "save_path", "total_size", "total_done", "time_added", "active_time", "ratio", "is_auto_managed", "stop_at_ratio", "remove_at_ratio", "stop_ratio", "label" }; private readonly IHttpClient _httpClient; private readonly Logger _logger; diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs index 058654854..bf690fab0 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs @@ -50,6 +50,9 @@ namespace NzbDrone.Core.Download.Clients.Deluge [FieldDefinition(6, Label = "Post-Import Category", Type = FieldType.Textbox, Advanced = true, HelpText = "Category for Lidarr to set after it has imported the download. Lidarr will not remove torrents in that category even if seeding finished. Leave blank to keep same category.")] public string MusicImportedCategory { get; set; } + [FieldDefinition(6, Label = "Failure Category", Type = FieldType.Textbox, Advanced = true, HelpText = "Category for Lidarr to treat a download as failed (applied externally). Leave blank to ignore.")] + public string MusicFailureCategory { get; set; } + [FieldDefinition(7, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(DelugePriority), HelpText = "Priority to use when grabbing albums released within the last 14 days")] public int RecentMusicPriority { get; set; } diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeTorrent.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeTorrent.cs index 680a163d9..e13f6cd60 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeTorrent.cs @@ -51,5 +51,8 @@ namespace NzbDrone.Core.Download.Clients.Deluge [JsonProperty(PropertyName = "stop_ratio")] public double StopRatio { get; set; } + + [JsonProperty(PropertyName = "label")] + public string Label { get; set; } } }