From 3481168df54e60a6d978364c302fa8711c1d255e Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 20 Oct 2022 20:03:55 -0500 Subject: [PATCH] Fixed: qBittorrent Updates Fixes #1658 Fixes #1536 --- .../Clients/QBittorrent/QBittorrent.cs | 5 +- .../Clients/QBittorrent/QBittorrentProxyV2.cs | 57 ++++++++++--------- .../QBittorrent/QBittorrentSettings.cs | 6 ++ .../Clients/QBittorrent/QBittorrentTorrent.cs | 2 +- 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index 7b3b2520f..06735be73 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -88,6 +88,8 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent if (!addHasSetShareLimits && setShareLimits) { + Proxy.SetTorrentSeedingConfiguration(hash.ToLower(), remoteBook.SeedConfiguration, Settings); + try { Proxy.SetTorrentSeedingConfiguration(hash.ToLower(), remoteBook.SeedConfiguration, Settings); @@ -286,7 +288,8 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent break; - case "forcedDL": //torrent is being downloaded, and was forced started + case "forcedDL": // torrent is being downloaded, and was forced started + case "forcedMetaDL": // torrent metadata is being forcibly downloaded case "moving": // torrent is being moved from a folder case "downloading": // torrent is being downloaded and data is being transferred item.Status = DownloadItemStatus.Downloading; diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs index 69d0125ad..dd1a09e2f 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs @@ -142,20 +142,8 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent var request = BuildRequest(settings).Resource("/api/v2/torrents/add") .Post() .AddFormParameter("urls", torrentUrl); - if (settings.MusicCategory.IsNotNullOrWhiteSpace()) - { - request.AddFormParameter("category", settings.MusicCategory); - } - // Note: ForceStart is handled by separate api call - if ((QBittorrentState)settings.InitialState == QBittorrentState.Start) - { - request.AddFormParameter("paused", false); - } - else if ((QBittorrentState)settings.InitialState == QBittorrentState.Pause) - { - request.AddFormParameter("paused", true); - } + AddTorrentDownloadFormParameters(request, settings); if (seedConfiguration != null) { @@ -177,20 +165,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent .Post() .AddFormUpload("torrents", fileName, fileContent); - if (settings.MusicCategory.IsNotNullOrWhiteSpace()) - { - request.AddFormParameter("category", settings.MusicCategory); - } - - // Note: ForceStart is handled by separate api call - if ((QBittorrentState)settings.InitialState == QBittorrentState.Start) - { - request.AddFormParameter("paused", false); - } - else if ((QBittorrentState)settings.InitialState == QBittorrentState.Pause) - { - request.AddFormParameter("paused", true); - } + AddTorrentDownloadFormParameters(request, settings); if (seedConfiguration != null) { @@ -259,6 +234,34 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent } } + private void AddTorrentDownloadFormParameters(HttpRequestBuilder request, QBittorrentSettings settings) + { + if (settings.MusicCategory.IsNotNullOrWhiteSpace()) + { + request.AddFormParameter("category", settings.MusicCategory); + } + + // Note: ForceStart is handled by separate api call + if ((QBittorrentState)settings.InitialState == QBittorrentState.Start) + { + request.AddFormParameter("paused", false); + } + else if ((QBittorrentState)settings.InitialState == QBittorrentState.Pause) + { + request.AddFormParameter("paused", true); + } + + if (settings.SequentialOrder) + { + request.AddFormParameter("sequentialDownload", true); + } + + if (settings.FirstAndLast) + { + request.AddFormParameter("firstLastPiecePrio", true); + } + } + public void SetTorrentSeedingConfiguration(string hash, TorrentSeedConfiguration seedConfiguration, QBittorrentSettings settings) { var request = BuildRequest(settings).Resource("/api/v2/torrents/setShareLimits") diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs index 7bd5df2c3..69670eb25 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs @@ -63,6 +63,12 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent [FieldDefinition(10, Label = "Initial State", Type = FieldType.Select, SelectOptions = typeof(QBittorrentState), HelpText = "Initial state for torrents added to qBittorrent. Note that Forced Torrents do not abide by seed restrictions")] public int InitialState { get; set; } + [FieldDefinition(11, Label = "Sequential Order", Type = FieldType.Checkbox, HelpText = "Download in sequential order (qBittorrent 4.1.0+)")] + public bool SequentialOrder { get; set; } + + [FieldDefinition(12, Label = "First and Last First", Type = FieldType.Checkbox, HelpText = "Download first and last pieces first (qBittorrent 4.1.0+)")] + public bool FirstAndLast { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs index 3007241bb..dbfceb0c3 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent public double Progress { get; set; } // Torrent progress (%/100) - public BigInteger Eta { get; set; } // Torrent ETA (seconds) + public BigInteger Eta { get; set; } // Torrent ETA (seconds) (QBit contains a bug exceeding ulong limits) public string State { get; set; } // Torrent state. See possible values here below