From 35365665cfd436ac276dd9591e23333bd26cf789 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 27 Sep 2023 12:06:30 -0700 Subject: [PATCH] Fixed: Completed downloads in Qbit missing import path --- .../QBittorrentTests/QBittorrentFixture.cs | 2 +- .../Clients/QBittorrent/QBittorrent.cs | 40 +++++++++++-------- .../Clients/QBittorrent/QBittorrentTorrent.cs | 3 -- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs index f0dc2ee8e..3ae0edd84 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs @@ -137,7 +137,7 @@ protected virtual void GivenTorrents(List torrents) { Mocker.GetMock() .Setup(s => s.GetTorrentProperties(torrent.Hash.ToLower(), It.IsAny())) - .Returns(new QBittorrentTorrentProperties { ContentPath = torrent.ContentPath, SavePath = torrent.SavePath }); + .Returns(new QBittorrentTorrentProperties { SavePath = torrent.SavePath }); Mocker.GetMock() .Setup(s => s.GetTorrentFiles(torrent.Hash.ToLower(), It.IsAny())) diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index 039723009..1be7aa14a 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -302,6 +302,19 @@ public override IEnumerable GetItems() break; } + if (version >= new Version("2.6.1") && item.Status == DownloadItemStatus.Completed) + { + if (torrent.ContentPath != torrent.SavePath) + { + item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.ContentPath)); + } + else + { + item.Status = DownloadItemStatus.Warning; + item.Message = "Unable to Import. Path matches client base download directory, it's possible 'Keep top-level folder' is disabled for this torrent or 'Torrent Content Layout' is NOT set to 'Original' or 'Create Subfolder'?"; + } + } + queueItems.Add(item); } @@ -315,22 +328,9 @@ public override void RemoveItem(DownloadClientItem item, bool deleteData) public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt) { - var properties = Proxy.GetTorrentProperties(item.DownloadId.ToLower(), Settings); - var savePath = new OsPath(properties.SavePath); - var version = Proxy.GetApiVersion(Settings); - - if (version >= new Version("2.6.1")) + // On API version >= 2.6.1 this is already set correctly + if (!item.OutputPath.IsEmpty) { - if (properties.ContentPath != savePath.ToString()) - { - item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(properties.ContentPath)); - } - else - { - item.Status = DownloadItemStatus.Warning; - item.Message = "Unable to Import. Path matches client base download directory, it's possible 'Keep top-level folder' is disabled for this torrent or 'Torrent Content Layout' is NOT set to 'Original' or 'Create Subfolder'?"; - } - return item; } @@ -341,6 +341,11 @@ public override DownloadClientItem GetImportItem(DownloadClientItem item, Downlo return item; } + var properties = Proxy.GetTorrentProperties(item.DownloadId.ToLower(), Settings); + var savePath = new OsPath(properties.SavePath); + + var result = item.Clone(); + // get the first subdirectory - QBittorrent returns `/` path separators even on windows... var relativePath = new OsPath(files[0].Name); while (!relativePath.Directory.IsEmpty) @@ -349,9 +354,10 @@ public override DownloadClientItem GetImportItem(DownloadClientItem item, Downlo } var outputPath = savePath + relativePath.FileName; - item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, outputPath); - return item; + result.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, outputPath); + + return result; } public override DownloadClientInfo GetStatus() diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs index ec5349680..92e6c7e02 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs @@ -48,9 +48,6 @@ public class QBittorrentTorrentProperties [JsonProperty(PropertyName = "seeding_time")] public long SeedingTime { get; set; } // Torrent seeding time (in seconds) - - [JsonProperty(PropertyName = "content_path")] - public string ContentPath { get; set; } // Torrent save path } public class QBittorrentTorrentFile