From ff894d52103927b0f6ae138cc78741dc5ce7bd93 Mon Sep 17 00:00:00 2001 From: lps-rocks Date: Fri, 7 Dec 2018 04:26:26 -0600 Subject: [PATCH] New: rTorrent - Don't start download automatically (#3222) --- .../RTorrentTests/RTorrentFixture.cs | 6 +-- .../Download/Clients/rTorrent/RTorrent.cs | 4 +- .../Clients/rTorrent/RTorrentProxy.cs | 50 +++++++++++++++---- .../Clients/rTorrent/RTorrentSettings.cs | 3 ++ 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/RTorrentTests/RTorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/RTorrentTests/RTorrentFixture.cs index 91fc1f0a0..89e6ff3df 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/RTorrentTests/RTorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/RTorrentTests/RTorrentFixture.cs @@ -54,11 +54,11 @@ public void Setup() protected void GivenSuccessfulDownload() { Mocker.GetMock() - .Setup(s => s.AddTorrentFromUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(s => s.AddTorrentFromUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback(PrepareClientToReturnCompletedItem); Mocker.GetMock() - .Setup(s => s.AddTorrentFromFile(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(s => s.AddTorrentFromFile(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback(PrepareClientToReturnCompletedItem); @@ -123,4 +123,4 @@ public void Download_should_return_unique_id() id.Should().NotBeNullOrEmpty(); } } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs index 3ea705dd2..114e72ed2 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs @@ -43,7 +43,7 @@ protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash { var priority = (RTorrentPriority)(remoteMovie.Movie.IsRecentMovie ? Settings.RecentMoviePriority : Settings.OlderMoviePriority); - _proxy.AddTorrentFromUrl(magnetLink, Settings.MovieCategory, priority, Settings.MovieDirectory, Settings); + _proxy.AddTorrentFromUrl(magnetLink, Settings.MovieCategory, priority, Settings.MovieDirectory, Settings.DontStartAutomatically, Settings); var tries = 10; var retryDelay = 500; @@ -63,7 +63,7 @@ protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string has { var priority = (RTorrentPriority)(remoteMovie.Movie.IsRecentMovie ? Settings.RecentMoviePriority : Settings.OlderMoviePriority); - _proxy.AddTorrentFromFile(filename, fileContent, Settings.MovieCategory, priority, Settings.MovieDirectory, Settings); + _proxy.AddTorrentFromFile(filename, fileContent, Settings.MovieCategory, priority, Settings.MovieDirectory, Settings.DontStartAutomatically, Settings); var tries = 10; var retryDelay = 500; diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentProxy.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentProxy.cs index dabe175a4..500715b46 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentProxy.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -13,8 +13,8 @@ public interface IRTorrentProxy string GetVersion(RTorrentSettings settings); List GetTorrents(RTorrentSettings settings); - void AddTorrentFromUrl(string torrentUrl, string label, RTorrentPriority priority, string directory, RTorrentSettings settings); - void AddTorrentFromFile(string fileName, byte[] fileContent, string label, RTorrentPriority priority, string directory, RTorrentSettings settings); + void AddTorrentFromUrl(string torrentUrl, string label, RTorrentPriority priority, string directory, bool doNotStart, RTorrentSettings settings); + void AddTorrentFromFile(string fileName, byte[] fileContent, string label, RTorrentPriority priority, string directory, bool doNotStart, RTorrentSettings settings); void RemoveTorrent(string hash, RTorrentSettings settings); bool HasHashTorrent(string hash, RTorrentSettings settings); } @@ -24,9 +24,15 @@ public interface IRTorrent : IXmlRpcProxy [XmlRpcMethod("d.multicall2")] object[] TorrentMulticall(params string[] parameters); + [XmlRpcMethod("load.normal")] + int Load(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); @@ -102,26 +108,50 @@ public List GetTorrents(RTorrentSettings settings) return items; } - public void AddTorrentFromUrl(string torrentUrl, string label, RTorrentPriority priority, string directory, RTorrentSettings settings) + public void AddTorrentFromUrl(string torrentUrl, string label, RTorrentPriority priority, string directory, bool doNotStart, RTorrentSettings settings) { - _logger.Debug("Executing remote method: load.normal"); + _logger.Debug("Adding Torrent From URL"); var client = BuildClient(settings); - var response = client.LoadStart("", torrentUrl, GetCommands(label, priority, directory)); + var response = -1; + + if (doNotStart) + { + _logger.Debug("Executing remote method load.normal"); + response = client.Load("", torrentUrl, GetCommands(label, priority, directory)); + } + else + { + _logger.Debug("Executing remote method load.start"); + response = client.LoadStart("", torrentUrl, GetCommands(label, priority, directory)); + } + if (response != 0) { throw new DownloadClientException("Could not add torrent: {0}.", torrentUrl); } } - public void AddTorrentFromFile(string fileName, byte[] fileContent, string label, RTorrentPriority priority, string directory, RTorrentSettings settings) + public void AddTorrentFromFile(string fileName, byte[] fileContent, string label, RTorrentPriority priority, string directory, bool doNotStart, RTorrentSettings settings) { - _logger.Debug("Executing remote method: load.raw"); + _logger.Debug("Loading Torrent from File"); var client = BuildClient(settings); - var response = client.LoadRawStart("", fileContent, GetCommands(label, priority, directory)); + var response = -1; + + if (doNotStart) + { + _logger.Debug("Executing remote method load.raw"); + response = client.LoadRaw("", fileContent, GetCommands(label, priority, directory)); + } + else + { + _logger.Debug("Executing remote method load.raw_start"); + response = client.LoadRawStart("", fileContent, GetCommands(label, priority, directory)); + } + if (response != 0) { throw new DownloadClientException("Could not add torrent: {0}.", fileName); @@ -202,4 +232,4 @@ private IRTorrent BuildClient(RTorrentSettings settings) return client; } } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs index 8dd886a09..7718c77f3 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrentSettings.cs @@ -59,6 +59,9 @@ public RTorrentSettings() [FieldDefinition(9, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(RTorrentPriority), HelpText = "Priority to use when grabbing movies that released over 21 days ago")] public int OlderMoviePriority { get; set; } + [FieldDefinition(10, Label = "Don't start download automatically", Type = FieldType.Checkbox, Advanced = true, HelpText = "Add Download in a stopped state. This is useful for letting a Queue manager like pyrotorque automatically start the download.")] + public bool DontStartAutomatically { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this));