From fa34af8f156628882d095aef632eba0bb0cc30b4 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 20 Aug 2017 21:29:02 -0700 Subject: [PATCH] uTorrent start/stop on add New: Start torrents added to uTorrent by default New: Option to add torrents to uTorrent in a stopped state Closes #2141 --- .../Download/Clients/uTorrent/UTorrent.cs | 18 +++++++++++++++++ .../Clients/uTorrent/UTorrentProxy.cs | 20 +++++++++++++++++++ .../Clients/uTorrent/UTorrentSettings.cs | 3 +++ 3 files changed, 41 insertions(+) diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs index 81dfff90b..b06a582d4 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs @@ -49,6 +49,15 @@ namespace NzbDrone.Core.Download.Clients.UTorrent _proxy.MoveTorrentToTopInQueue(hash, Settings); } + if (Settings.AddStopped) + { + _proxy.StopTorrent(hash, Settings); + } + else + { + _proxy.StartTorrent(hash, Settings); + } + return hash; } @@ -65,6 +74,15 @@ namespace NzbDrone.Core.Download.Clients.UTorrent _proxy.MoveTorrentToTopInQueue(hash, Settings); } + if (Settings.AddStopped) + { + _proxy.StopTorrent(hash, Settings); + } + else + { + _proxy.StartTorrent(hash, Settings); + } + return hash; } diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs index 123e121e0..ffca992aa 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs @@ -22,6 +22,8 @@ namespace NzbDrone.Core.Download.Clients.UTorrent void RemoveTorrent(string hash, bool removeData, UTorrentSettings settings); void SetTorrentLabel(string hash, string label, UTorrentSettings settings); void MoveTorrentToTopInQueue(string hash, UTorrentSettings settings); + void StartTorrent(string hash, UTorrentSettings settings); + void StopTorrent(string hash, UTorrentSettings settings); } public class UTorrentProxy : IUTorrentProxy @@ -157,6 +159,24 @@ namespace NzbDrone.Core.Download.Clients.UTorrent ProcessRequest(requestBuilder, settings); } + public void StartTorrent(string hash, UTorrentSettings settings) + { + var requestBuilder = BuildRequest(settings) + .AddQueryParam("action", "start") + .AddQueryParam("hash", hash); + + ProcessRequest(requestBuilder, settings); + } + + public void StopTorrent(string hash, UTorrentSettings settings) + { + var requestBuilder = BuildRequest(settings) + .AddQueryParam("action", "stop") + .AddQueryParam("hash", hash); + + ProcessRequest(requestBuilder, settings); + } + private HttpRequestBuilder BuildRequest(UTorrentSettings settings) { var requestBuilder = new HttpRequestBuilder(false, settings.Host, settings.Port) diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs index 52185b134..149cb89ab 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs @@ -47,6 +47,9 @@ namespace NzbDrone.Core.Download.Clients.UTorrent [FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(UTorrentPriority), HelpText = "Priority to use when grabbing episodes that aired over 14 days ago")] public int OlderTvPriority { get; set; } + [FieldDefinition(7, Label = "Add Stopped", Type = FieldType.Checkbox, SelectOptions = typeof(UTorrentPriority), HelpText = "Torrents will need to be started manually in uTorrent")] + public bool AddStopped { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this));