diff --git a/src/NzbDrone.Core/Download/Clients/Aria2/Aria2.cs b/src/NzbDrone.Core/Download/Clients/Aria2/Aria2.cs index b008e070a..0e13b49af 100644 --- a/src/NzbDrone.Core/Download/Clients/Aria2/Aria2.cs +++ b/src/NzbDrone.Core/Download/Clients/Aria2/Aria2.cs @@ -127,10 +127,8 @@ namespace NzbDrone.Core.Download.Clients.Aria2 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(), @@ -144,7 +142,12 @@ namespace NzbDrone.Core.Download.Clients.Aria2 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 02639664a..22ed44a40 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs @@ -87,7 +87,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole { 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, @@ -99,11 +99,14 @@ namespace NzbDrone.Core.Download.Clients.Blackhole 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 faaff7112..0b9bf7f13 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs @@ -188,6 +188,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge // Here we detect if Deluge is managing the torrent and whether the seed criteria has been met. // This allows drone 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 664900f60..1c31bbd9a 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -86,7 +86,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation } } - var item = new DownloadClientItem() + var item = new DownloadClientItem { Category = Settings.MusicCategory, DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this, false), @@ -97,11 +97,11 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation 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 3c775d563..f8cfeeed0 100644 --- a/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs +++ b/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs @@ -143,7 +143,7 @@ namespace NzbDrone.Core.Download.Clients.Flood 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); @@ -155,7 +155,7 @@ namespace NzbDrone.Core.Download.Clients.Flood // 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 3109aed0f..b83615c18 100644 --- a/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs +++ b/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs @@ -116,7 +116,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload 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 261bce3da..d97645b3c 100644 --- a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs +++ b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs @@ -90,7 +90,10 @@ namespace NzbDrone.Core.Download.Clients.Hadouken 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 d25176d2b..745f6f72f 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -237,7 +237,10 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent // 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 89d2eaa77..465df1ee8 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs @@ -117,7 +117,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission 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 a7e207f7f..c68e1c15d 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs @@ -180,7 +180,7 @@ namespace NzbDrone.Core.Download.Clients.RTorrent // 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 60cf79c5f..72c7ec827 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs @@ -165,6 +165,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent // '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 @@ namespace NzbDrone.Core.Download 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 @@ namespace NzbDrone.Core.Download 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/TrackImport/ImportApprovedTracks.cs b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs index 6c15d475e..1c5f46343 100644 --- a/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs +++ b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs @@ -222,7 +222,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport { default: case ImportMode.Auto: - copyOnly = downloadClientItem != null && !downloadClientItem.CanMoveFiles; + copyOnly = downloadClientItem is { CanMoveFiles: false }; break; case ImportMode.Move: copyOnly = false;