From 9a1660da51091c351b90408edb47d324d347632e Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 30 Aug 2018 23:04:40 -0400 Subject: [PATCH] New: Add stopped option for rTorrent Co-Authored-By: Mark McDowall --- .../Clients/rTorrent/RTorrentPriority.cs | 2 +- .../Clients/rTorrent/RTorrentProxy.cs | 38 ++++++++++++++++--- .../Clients/rTorrent/RTorrentSettings.cs | 3 ++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentPriority.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentPriority.cs index 99b289e8e..9ae5395d3 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentPriority.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentPriority.cs @@ -2,7 +2,7 @@ namespace NzbDrone.Core.Download.Clients.RTorrent { public enum RTorrentPriority { - DoNotDownload = 0, + VeryLow = 0, Low = 1, Normal = 2, High = 3 diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentProxy.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentProxy.cs index c00df292e..ff9a4332f 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentProxy.cs @@ -26,9 +26,15 @@ namespace NzbDrone.Core.Download.Clients.RTorrent [XmlRpcMethod("d.multicall2")] object[] TorrentMulticall(params string[] parameters); + [XmlRpcMethod("load.normal")] + int LoadNormal(string target, string data, params string[] commands); + [XmlRpcMethod("load.start")] int LoadStart(string target, string data, params string[] commands); + [XmlRpcMethod("load.raw")] + int LoadRaw(string target, byte[] data, params string[] commands); + [XmlRpcMethod("load.raw_start")] int LoadRawStart(string target, byte[] data, params string[] commands); @@ -107,10 +113,20 @@ namespace NzbDrone.Core.Download.Clients.RTorrent public void AddTorrentFromUrl(string torrentUrl, string label, RTorrentPriority priority, string directory, RTorrentSettings settings) { - _logger.Debug("Executing remote method: load.normal"); - var client = BuildClient(settings); - var response = ExecuteRequest(() => client.LoadStart("", torrentUrl, GetCommands(label, priority, directory))); + var response = ExecuteRequest(() => + { + if (settings.AddStopped) + { + _logger.Debug("Executing remote method: load.normal"); + return client.LoadNormal("", torrentUrl, GetCommands(label, priority, directory)); + } + else + { + _logger.Debug("Executing remote method: load.start"); + return client.LoadStart("", torrentUrl, GetCommands(label, priority, directory)); + } + }); if (response != 0) { @@ -120,10 +136,20 @@ namespace NzbDrone.Core.Download.Clients.RTorrent public void AddTorrentFromFile(string fileName, byte[] fileContent, string label, RTorrentPriority priority, string directory, RTorrentSettings settings) { - _logger.Debug("Executing remote method: load.raw"); - var client = BuildClient(settings); - var response = ExecuteRequest(() => client.LoadRawStart("", fileContent, GetCommands(label, priority, directory))); + var response = ExecuteRequest(() => + { + if (settings.AddStopped) + { + _logger.Debug("Executing remote method: load.raw"); + return client.LoadRaw("", fileContent, GetCommands(label, priority, directory)); + } + else + { + _logger.Debug("Executing remote method: load.raw_start"); + return client.LoadRawStart("", fileContent, GetCommands(label, priority, directory)); + } + }); if (response != 0) { diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs index c309a10eb..e2fc57dc8 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs @@ -61,6 +61,9 @@ namespace NzbDrone.Core.Download.Clients.RTorrent [FieldDefinition(9, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(RTorrentPriority), HelpText = "Priority to use when grabbing albums released over 14 days ago")] public int OlderTvPriority { get; set; } + [FieldDefinition(10, Label = "Add Stopped", Type = FieldType.Checkbox, HelpText = "Enabling will prevent magnets from downloading before downloading")] + public bool AddStopped { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this));