From 7c0229c4e44a7c3deabc6a3e6e160a36b9f0cdbe Mon Sep 17 00:00:00 2001 From: Mathis Date: Mon, 21 Feb 2022 21:20:58 +0100 Subject: [PATCH] New: Add qBittorrent sequential order and first and last piece priority options Fixes #2660 --- .../Clients/QBittorrent/QBittorrentProxyV2.cs | 57 ++++++++++--------- .../QBittorrent/QBittorrentSettings.cs | 6 ++ 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs index 879106cae..104a03d83 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 827ef7bc2..763200c37 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")] 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));