From 87c4190db64295bbe8ae21a7bc6b61519f546e44 Mon Sep 17 00:00:00 2001 From: doguitar Date: Thu, 5 May 2022 09:15:06 -0700 Subject: [PATCH] deluge: create a category for lidarr to consider a download failed. category can be applied by an external tool to handle stalled downloads. --- .../Download/Clients/Deluge/Deluge.cs | 33 ++++++++++++++++--- .../Download/Clients/Deluge/DelugeProxy.cs | 2 +- .../Download/Clients/Deluge/DelugeSettings.cs | 3 ++ .../Download/Clients/Deluge/DelugeTorrent.cs | 3 ++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs index f9f292f68..dd502f93b 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs @@ -119,6 +119,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) @@ -152,7 +159,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"; @@ -278,9 +289,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; @@ -333,6 +344,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 370cdffb2..36efa7e94 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs @@ -32,7 +32,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 316d39906..154f0e35e 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 RecentTvPriority { 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; } } }