From 05b64406a4bdf87909f600175a668109bd0663bf Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:50:06 -0500 Subject: [PATCH] Fixed: Only apply remote path mappings for completed items in Qbit (cherry picked from commit 583eb52ddc01b608ab6cb17e863a8830c17b7b75) --- .../QBittorrentTests/QBittorrentFixture.cs | 4 +- .../Clients/QBittorrent/QBittorrent.cs | 40 ++++++++----------- .../Clients/QBittorrent/QBittorrentTorrent.cs | 3 ++ 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs index bdf7cd31c..7150c35d6 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 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests { Mocker.GetMock() .Setup(s => s.GetTorrentProperties(torrent.Hash.ToLower(), It.IsAny())) - .Returns(new QBittorrentTorrentProperties { SavePath = torrent.SavePath }); + .Returns(new QBittorrentTorrentProperties { ContentPath = torrent.ContentPath, SavePath = torrent.SavePath }); Mocker.GetMock() .Setup(s => s.GetTorrentFiles(torrent.Hash.ToLower(), It.IsAny())) @@ -405,7 +405,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests Size = 1000, Progress = 0.7, Eta = 8640000, - State = "stalledDL", + State = "pausedUP", Label = "", SavePath = @"C:\Torrents".AsOsAgnostic(), ContentPath = @"C:\Torrents\Droned.S01.12".AsOsAgnostic() diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index 56324d28b..9c16376bd 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -304,19 +304,6 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent break; } - if (version >= new Version("2.6.1")) - { - if (torrent.ContentPath != torrent.SavePath) - { - item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.ContentPath)); - } - else if (item.Status == DownloadItemStatus.Completed) - { - 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); } @@ -330,9 +317,22 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt) { - // On API version >= 2.6.1 this is already set correctly - if (!item.OutputPath.IsEmpty) + 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")) { + 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; } @@ -343,11 +343,6 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent 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) @@ -356,10 +351,9 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent } var outputPath = savePath + relativePath.FileName; + item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, outputPath); - result.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, outputPath); - - return result; + return item; } 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 92e6c7e02..ec5349680 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs @@ -48,6 +48,9 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent [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