From 29ef75960dc62411dad71f0640b56d3302f39c08 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 31 Jul 2024 07:27:19 +0300 Subject: [PATCH] Fixed: Moving files for torrents when Remove Completed is disabled (cherry picked from commit 78a0def46a4c8628d9bcf6af2701aa35b3f959b9) Fixed: Moving files on import for usenet clients (cherry picked from commit 291d792810d071f28c389d100b9642854d7cd70e) --- .../MovieImport/ImportApprovedMoviesFixture.cs | 4 ++-- src/NzbDrone.Core/Download/Clients/Aria2/Aria2.cs | 9 ++++++--- .../Download/Clients/Blackhole/TorrentBlackhole.cs | 13 ++++++++----- src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs | 1 + .../DownloadStation/TorrentDownloadStation.cs | 8 ++++---- src/NzbDrone.Core/Download/Clients/Flood/Flood.cs | 4 ++-- .../FreeboxDownload/TorrentFreeboxDownload.cs | 2 +- .../Download/Clients/Hadouken/Hadouken.cs | 5 ++++- .../Download/Clients/QBittorrent/QBittorrent.cs | 7 +++++-- .../Clients/Transmission/TransmissionBase.cs | 2 +- .../Download/Clients/rTorrent/RTorrent.cs | 2 +- .../Download/Clients/uTorrent/UTorrent.cs | 1 + src/NzbDrone.Core/Download/DownloadClientItem.cs | 2 ++ .../MediaFiles/MovieImport/ImportApprovedMovie.cs | 2 +- 14 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/ImportApprovedMoviesFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/ImportApprovedMoviesFixture.cs index f9ed898d8..f408ae8bc 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/ImportApprovedMoviesFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/ImportApprovedMoviesFixture.cs @@ -67,8 +67,8 @@ public void Setup() .Returns(new List()); _downloadClientItem = Builder.CreateNew() - .With(d => d.OutputPath = new OsPath(outputPath)) - .Build(); + .With(d => d.OutputPath = new OsPath(outputPath)) + .Build(); } private void GivenNewDownload() diff --git a/src/NzbDrone.Core/Download/Clients/Aria2/Aria2.cs b/src/NzbDrone.Core/Download/Clients/Aria2/Aria2.cs index 74607a33a..a7e11041d 100644 --- a/src/NzbDrone.Core/Download/Clients/Aria2/Aria2.cs +++ b/src/NzbDrone.Core/Download/Clients/Aria2/Aria2.cs @@ -129,10 +129,8 @@ public override IEnumerable GetItems() var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(GetOutputPath(torrent))); - yield return new DownloadClientItem + var queueItem = new DownloadClientItem { - CanMoveFiles = false, - CanBeRemoved = torrent.Status == "complete", Category = null, DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this, false), DownloadId = torrent.InfoHash?.ToUpper(), @@ -146,7 +144,12 @@ public override IEnumerable GetItems() Status = status, Title = title, TotalSize = totalLength, + CanMoveFiles = false }; + + queueItem.CanBeRemoved = queueItem.DownloadClientInfo.RemoveCompletedDownloads && torrent.Status == "complete"; + + yield return queueItem; } } diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs index 9a75a0238..b6fe511fb 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs @@ -89,7 +89,7 @@ public override IEnumerable GetItems() { foreach (var item in _scanWatchFolder.GetItems(Settings.WatchFolder, ScanGracePeriod)) { - yield return new DownloadClientItem + var queueItem = new DownloadClientItem { DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this, false), DownloadId = Definition.Name + "_" + item.DownloadId, @@ -101,11 +101,14 @@ public override IEnumerable GetItems() OutputPath = item.OutputPath, - Status = item.Status, - - CanMoveFiles = !Settings.ReadOnly, - CanBeRemoved = !Settings.ReadOnly + Status = item.Status }; + + queueItem.CanMoveFiles = queueItem.CanBeRemoved = + queueItem.DownloadClientInfo.RemoveCompletedDownloads && + !Settings.ReadOnly; + + yield return queueItem; } } diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs index e5d593a1a..2971bd059 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs @@ -190,6 +190,7 @@ public override IEnumerable GetItems() // Here we detect if Deluge is managing the torrent and whether the seed criteria has been met. // This allows Radarr to delete the torrent as appropriate. item.CanMoveFiles = item.CanBeRemoved = + item.DownloadClientInfo.RemoveCompletedDownloads && torrent.IsAutoManaged && torrent.StopAtRatio && torrent.Ratio >= torrent.StopRatio && diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs index 5e06a3b10..3f89d3e31 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -88,7 +88,7 @@ public override IEnumerable GetItems() } } - var item = new DownloadClientItem() + var item = new DownloadClientItem { Category = Settings.TvCategory, DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this, false), @@ -99,11 +99,11 @@ public override IEnumerable GetItems() RemainingTime = GetRemainingTime(torrent), SeedRatio = GetSeedRatio(torrent), Status = GetStatus(torrent), - Message = GetMessage(torrent), - CanMoveFiles = IsFinished(torrent), - CanBeRemoved = IsFinished(torrent) + Message = GetMessage(torrent) }; + item.CanMoveFiles = item.CanBeRemoved = item.DownloadClientInfo.RemoveCompletedDownloads && IsFinished(torrent); + if (item.Status == DownloadItemStatus.Completed || item.Status == DownloadItemStatus.Failed) { item.OutputPath = GetOutputPath(outputPath, torrent, serialNumber); diff --git a/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs b/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs index 10a4aaf2c..046433e69 100644 --- a/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs +++ b/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs @@ -153,7 +153,7 @@ public override IEnumerable GetItems() item.Status = DownloadItemStatus.Downloading; } - if (item.Status == DownloadItemStatus.Completed) + if (item.DownloadClientInfo.RemoveCompletedDownloads && item.Status == DownloadItemStatus.Completed) { // Grab cached seedConfig var seedConfig = _downloadSeedConfigProvider.GetSeedConfiguration(item.DownloadId); @@ -165,7 +165,7 @@ public override IEnumerable GetItems() // Check if seed ratio reached item.CanMoveFiles = item.CanBeRemoved = true; } - else if (properties.DateFinished != null && properties.DateFinished > 0) + else if (properties.DateFinished is > 0) { // Check if seed time reached if ((DateTimeOffset.Now - DateTimeOffset.FromUnixTimeSeconds((long)properties.DateFinished)) >= seedConfig.SeedTime) diff --git a/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs b/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs index 690829c5d..e32174cf8 100644 --- a/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs +++ b/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs @@ -119,7 +119,7 @@ public override IEnumerable GetItems() break; } - item.CanBeRemoved = item.CanMoveFiles = torrent.Status == FreeboxDownloadTaskStatus.Done; + item.CanBeRemoved = item.CanMoveFiles = item.DownloadClientInfo.RemoveCompletedDownloads && torrent.Status == FreeboxDownloadTaskStatus.Done; queueItems.Add(item); } diff --git a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs index 2cac85d25..1b1a0622b 100644 --- a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs +++ b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs @@ -103,7 +103,10 @@ public override IEnumerable GetItems() item.Status = DownloadItemStatus.Downloading; } - item.CanMoveFiles = item.CanBeRemoved = torrent.IsFinished && torrent.State == HadoukenTorrentState.Paused; + item.CanMoveFiles = item.CanBeRemoved = + item.DownloadClientInfo.RemoveCompletedDownloads && + torrent.IsFinished && + torrent.State == HadoukenTorrentState.Paused; items.Add(item); } diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index de969c52e..d53335465 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -225,7 +225,7 @@ public override IEnumerable GetItems() foreach (var torrent in torrents) { - var item = new DownloadClientItem() + var item = new DownloadClientItem { DownloadId = torrent.Hash.ToUpper(), Category = torrent.Category.IsNotNullOrWhiteSpace() ? torrent.Category : torrent.Label, @@ -239,7 +239,10 @@ public override IEnumerable GetItems() // Avoid removing torrents that haven't reached the global max ratio. // Removal also requires the torrent to be paused, in case a higher max ratio was set on the torrent itself (which is not exposed by the api). - item.CanMoveFiles = item.CanBeRemoved = torrent.State is "pausedUP" or "stoppedUP" && HasReachedSeedLimit(torrent, config); + item.CanMoveFiles = item.CanBeRemoved = + item.DownloadClientInfo.RemoveCompletedDownloads && + torrent.State is "pausedUP" or "stoppedUP" && + HasReachedSeedLimit(torrent, config); switch (torrent.State) { diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs index c1d341231..fc8f75686 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs @@ -119,7 +119,7 @@ public override IEnumerable GetItems() item.Status = DownloadItemStatus.Downloading; } - item.CanBeRemoved = HasReachedSeedLimit(torrent, item.SeedRatio, configFunc); + item.CanBeRemoved = item.DownloadClientInfo.RemoveCompletedDownloads && HasReachedSeedLimit(torrent, item.SeedRatio, configFunc); item.CanMoveFiles = item.CanBeRemoved && torrent.Status == TransmissionTorrentStatus.Stopped; items.Add(item); diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs index 6eaccb55b..2c61ea2d9 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs @@ -185,7 +185,7 @@ public override IEnumerable GetItems() // Grab cached seedConfig var seedConfig = _downloadSeedConfigProvider.GetSeedConfiguration(torrent.Hash); - if (torrent.IsFinished && seedConfig != null) + if (item.DownloadClientInfo.RemoveCompletedDownloads && torrent.IsFinished && seedConfig != null) { var canRemove = false; diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs index 5b9537430..e57d55ebe 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs @@ -167,6 +167,7 @@ public override IEnumerable GetItems() // 'Started' without 'Queued' is when the torrent is 'forced seeding' item.CanMoveFiles = item.CanBeRemoved = + item.DownloadClientInfo.RemoveCompletedDownloads && !torrent.Status.HasFlag(UTorrentTorrentStatus.Queued) && !torrent.Status.HasFlag(UTorrentTorrentStatus.Started); diff --git a/src/NzbDrone.Core/Download/DownloadClientItem.cs b/src/NzbDrone.Core/Download/DownloadClientItem.cs index c32afa1e3..720cb3055 100644 --- a/src/NzbDrone.Core/Download/DownloadClientItem.cs +++ b/src/NzbDrone.Core/Download/DownloadClientItem.cs @@ -38,6 +38,7 @@ public class DownloadClientItemClientInfo public string Type { get; set; } public int Id { get; set; } public string Name { get; set; } + public bool RemoveCompletedDownloads { get; set; } public bool HasPostImportCategory { get; set; } public static DownloadClientItemClientInfo FromDownloadClient( @@ -50,6 +51,7 @@ public static DownloadClientItemClientInfo FromDownloadClient( Type = downloadClient.Name, Id = downloadClient.Definition.Id, Name = downloadClient.Definition.Name, + RemoveCompletedDownloads = downloadClient.Definition is DownloadClientDefinition { RemoveCompletedDownloads: true }, HasPostImportCategory = hasPostImportCategory }; } diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs index 56016dda6..ef25f2197 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs @@ -118,7 +118,7 @@ public List Import(List decisions, bool newDownloa { default: case ImportMode.Auto: - copyOnly = downloadClientItem != null && !downloadClientItem.CanMoveFiles; + copyOnly = downloadClientItem is { CanMoveFiles: false }; break; case ImportMode.Move: copyOnly = false;