From 4b22200708ca120cfdcf9cb796be92183adb95d1 Mon Sep 17 00:00:00 2001
From: Mark McDowall <mark@mcdowall.ca>
Date: Sat, 25 Nov 2023 15:52:01 -0800
Subject: [PATCH] New: Add qBittorrent option for Content Layout

Closes #6213
---
 .../Clients/QBittorrent/QBittorrentContentLayout.cs      | 9 +++++++++
 .../Download/Clients/QBittorrent/QBittorrentProxyV2.cs   | 9 +++++++++
 .../Download/Clients/QBittorrent/QBittorrentSettings.cs  | 3 +++
 src/NzbDrone.Core/Localization/Core/en.json              | 2 ++
 4 files changed, 23 insertions(+)
 create mode 100644 src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentContentLayout.cs

diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentContentLayout.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentContentLayout.cs
new file mode 100644
index 000000000..874fbff7a
--- /dev/null
+++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentContentLayout.cs
@@ -0,0 +1,9 @@
+namespace NzbDrone.Core.Download.Clients.QBittorrent
+{
+    public enum QBittorrentContentLayout
+    {
+        Default = 0,
+        Original = 1,
+        Subfolder = 2
+    }
+}
diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs
index d59892bfd..ab0c2e5a9 100644
--- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs
+++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs
@@ -266,6 +266,15 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
             {
                 request.AddFormParameter("firstLastPiecePrio", true);
             }
+
+            if ((QBittorrentContentLayout)settings.ContentLayout == QBittorrentContentLayout.Original)
+            {
+                request.AddFormParameter("contentLayout", "Original");
+            }
+            else if ((QBittorrentContentLayout)settings.ContentLayout == QBittorrentContentLayout.Subfolder)
+            {
+                request.AddFormParameter("contentLayout", "Subfolder");
+            }
         }
 
         public void SetTorrentSeedingConfiguration(string hash, TorrentSeedConfiguration seedConfiguration, QBittorrentSettings settings)
diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs
index d092703ad..2ad3ae163 100644
--- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs
+++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentSettings.cs
@@ -71,6 +71,9 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
         [FieldDefinition(12, Label = "DownloadClientQbittorrentSettingsFirstAndLastFirst", Type = FieldType.Checkbox, HelpText = "DownloadClientQbittorrentSettingsFirstAndLastFirstHelpText")]
         public bool FirstAndLast { get; set; }
 
+        [FieldDefinition(13, Label = "DownloadClientQbittorrentSettingsContentLayout", Type = FieldType.Select, SelectOptions = typeof(QBittorrentContentLayout), HelpText = "DownloadClientQbittorrentSettingsContentLayoutHelpText")]
+        public int ContentLayout { 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 1a8eb8a3f..ef384145d 100644
--- a/src/NzbDrone.Core/Localization/Core/en.json
+++ b/src/NzbDrone.Core/Localization/Core/en.json
@@ -418,6 +418,8 @@
   "DownloadClientPneumaticSettingsStrmFolderHelpText": ".strm files in this folder will be import by drone",
   "DownloadClientQbittorrentSettingsFirstAndLastFirst": "First and Last First",
   "DownloadClientQbittorrentSettingsFirstAndLastFirstHelpText": "Download first and last pieces first (qBittorrent 4.1.0+)",
+  "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+)",
   "DownloadClientQbittorrentSettingsInitialStateHelpText": "Initial state for torrents added to qBittorrent. Note that Forced Torrents do not abide by seed restrictions",
   "DownloadClientQbittorrentSettingsSequentialOrder": "Sequential Order",
   "DownloadClientQbittorrentSettingsSequentialOrderHelpText": "Download in sequential order (qBittorrent 4.1.0+)",
