From cea5ee503fcb64895d21623d38dfe522e6975f7c Mon Sep 17 00:00:00 2001 From: nopoz Date: Sat, 2 Mar 2024 21:22:03 -0800 Subject: [PATCH] New: Add download directory & move completed for Deluge (cherry picked from commit 07bd159436935a7adb87ae1b6924a4d42d719b0f) --- .../Download/Clients/Deluge/DelugeProxy.cs | 38 +++++++++++++++---- .../Download/Clients/Deluge/DelugeSettings.cs | 6 +++ src/NzbDrone.Core/Localization/Core/en.json | 4 ++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs index 4b012efa0..e6071fb53 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Dynamic; using System.Linq; using System.Net; using Newtonsoft.Json.Linq; using NLog; using NzbDrone.Common.Cache; +using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Common.Serializer; @@ -101,11 +103,21 @@ namespace NzbDrone.Core.Download.Clients.Deluge public string AddTorrentFromMagnet(string magnetLink, DelugeSettings settings) { - var options = new + dynamic options = new ExpandoObject(); + + options.add_paused = settings.AddPaused; + options.remove_at_ratio = false; + + if (settings.DownloadDirectory.IsNotNullOrWhiteSpace()) + { + options.download_location = settings.DownloadDirectory; + } + + if (settings.CompletedDirectory.IsNotNullOrWhiteSpace()) { - add_paused = settings.AddPaused, - remove_at_ratio = false - }; + options.move_completed_path = settings.CompletedDirectory; + options.move_completed = true; + } var response = ProcessRequest(settings, "core.add_torrent_magnet", magnetLink, options); @@ -114,11 +126,21 @@ namespace NzbDrone.Core.Download.Clients.Deluge public string AddTorrentFromFile(string filename, byte[] fileContent, DelugeSettings settings) { - var options = new + dynamic options = new ExpandoObject(); + + options.add_paused = settings.AddPaused; + options.remove_at_ratio = false; + + if (settings.DownloadDirectory.IsNotNullOrWhiteSpace()) + { + options.download_location = settings.DownloadDirectory; + } + + if (settings.CompletedDirectory.IsNotNullOrWhiteSpace()) { - add_paused = settings.AddPaused, - remove_at_ratio = false - }; + options.move_completed_path = settings.CompletedDirectory; + options.move_completed = true; + } var response = ProcessRequest(settings, "core.add_torrent_file", filename, fileContent, options); return response; diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs index 42d579d8d..058654854 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs @@ -59,6 +59,12 @@ namespace NzbDrone.Core.Download.Clients.Deluge [FieldDefinition(9, Label = "Add Paused", Type = FieldType.Checkbox)] public bool AddPaused { get; set; } + [FieldDefinition(10, Label = "DownloadClientDelugeSettingsDirectory", Type = FieldType.Textbox, Advanced = true, HelpText = "DownloadClientDelugeSettingsDirectoryHelpText")] + public string DownloadDirectory { get; set; } + + [FieldDefinition(11, Label = "DownloadClientDelugeSettingsDirectoryCompleted", Type = FieldType.Textbox, Advanced = true, HelpText = "DownloadClientDelugeSettingsDirectoryCompletedHelpText")] + public string CompletedDirectory { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index b903ae491..077e7e289 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -362,6 +362,10 @@ "DownloadClientCheckDownloadingToRoot": "Download client {0} places downloads in the root folder {1}. You should not download to a root folder.", "DownloadClientCheckNoneAvailableMessage": "No download client is available", "DownloadClientCheckUnableToCommunicateMessage": "Unable to communicate with {0}.", + "DownloadClientDelugeSettingsDirectory": "Download Directory", + "DownloadClientDelugeSettingsDirectoryCompleted": "Move When Completed Directory", + "DownloadClientDelugeSettingsDirectoryCompletedHelpText": "Optional location to move completed downloads to, leave blank to use the default Deluge location", + "DownloadClientDelugeSettingsDirectoryHelpText": "Optional location to put downloads in, leave blank to use the default Deluge location", "DownloadClientPriorityHelpText": "Download Client Priority from 1 (Highest) to 50 (Lowest). Default: 1. Round-Robin is used for clients with the same priority.", "DownloadClientQbittorrentSettingsContentLayout": "Content Layout", "DownloadClientQbittorrentSettingsContentLayoutHelpText": "Whether to use qBittorrent's configured content layout, the original layout from the torrent or always create a subfolder (qBittorrent 4.3.2+)",