From 19a4d3536bde8103c4e0f7414cc1819b2083ffb2 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 22 Aug 2017 20:48:53 -0700 Subject: [PATCH] New: Initial state for torrents added to UTorrent Closes #409 --- .../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 b06a582d4..e02bf646c 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 ffca992aa..c65e37c28 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 149cb89ab..bd88f901c 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 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; } + [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..17feaa485 --- /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 afdbf7791..e7af7236f 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -495,6 +495,7 @@ +