From 7d64bb403f204313293ba56c3d4e935b160c91e7 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 29 Oct 2017 17:22:14 -0400 Subject: [PATCH] New: Initial state for torrents added to UTorrent --- .../Download/Clients/uTorrent/UTorrent.cs | 18 ++---------------- .../Download/Clients/uTorrent/UTorrentProxy.cs | 16 +++------------- .../Clients/uTorrent/UTorrentSettings.cs | 4 ++-- .../Download/Clients/uTorrent/UtorrentState.cs | 10 ++++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 5 files changed, 18 insertions(+), 31 deletions(-) create mode 100644 src/NzbDrone.Core/Download/Clients/uTorrent/UtorrentState.cs diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs index d6df4c2e8..d82178e81 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs @@ -49,14 +49,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent _proxy.MoveTorrentToTopInQueue(hash, Settings); } - if (Settings.AddStopped) - { - _proxy.StopTorrent(hash, Settings); - } - else - { - _proxy.StartTorrent(hash, Settings); - } + _proxy.SetState(hash, (UTorrentState)Settings.IntialState, Settings); return hash; } @@ -74,14 +67,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent _proxy.MoveTorrentToTopInQueue(hash, Settings); } - if (Settings.AddStopped) - { - _proxy.StopTorrent(hash, Settings); - } - else - { - _proxy.StartTorrent(hash, Settings); - } + _proxy.SetState(hash, (UTorrentState)Settings.IntialState, Settings); return hash; } diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs index 08d0c8186..c594ebb58 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs @@ -22,8 +22,7 @@ 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); + void SetState(string hash, UTorrentState state, UTorrentSettings settings); } public class UTorrentProxy : IUTorrentProxy @@ -159,19 +158,10 @@ namespace NzbDrone.Core.Download.Clients.UTorrent ProcessRequest(requestBuilder, settings); } - public void StartTorrent(string hash, UTorrentSettings settings) + public void SetState(string hash, UTorrentState state, 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("action", state.ToString().ToLowerInvariant()) .AddQueryParam("hash", hash); ProcessRequest(requestBuilder, settings); diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs index 30ab7f4df..2a7df8c18 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs @@ -47,8 +47,8 @@ namespace NzbDrone.Core.Download.Clients.UTorrent [FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(UTorrentPriority), HelpText = "Priority to use when grabbing albums released 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; } + [FieldDefinition(7, Label = "Initial State", Type = FieldType.Select, SelectOptions = typeof(UTorrentState), HelpText = "Initial state for torrents added to uTorrent")] + public int IntialState { get; set; } public NzbDroneValidationResult Validate() { diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UtorrentState.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UtorrentState.cs new file mode 100644 index 000000000..db5d3da87 --- /dev/null +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UtorrentState.cs @@ -0,0 +1,10 @@ +namespace NzbDrone.Core.Download.Clients.UTorrent +{ + public enum UTorrentState + { + Start = 0, + ForceStart = 1, + Pause = 2, + Stop = 3 + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 9c82d21bf..d01e33b0a 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -372,6 +372,7 @@ +