diff --git a/src/NzbDrone.Core/Datastore/Migration/158_cdh_per_downloadclient.cs b/src/NzbDrone.Core/Datastore/Migration/158_cdh_per_downloadclient.cs index c26e33a72..00316fccb 100644 --- a/src/NzbDrone.Core/Datastore/Migration/158_cdh_per_downloadclient.cs +++ b/src/NzbDrone.Core/Datastore/Migration/158_cdh_per_downloadclient.cs @@ -36,7 +36,7 @@ private void MoveRemoveSettings(IDbConnection conn, IDbTransaction tran) removeFailedDownloads = true; } - using (var updateClientCmd = conn.CreateCommand(tran, $"UPDATE DownloadClients SET RemoveCompletedDownloads = (CASE WHEN Implementation = \"RTorrent\" THEN 0 ELSE ? END), RemoveFailedDownloads = ?")) + using (var updateClientCmd = conn.CreateCommand(tran, $"UPDATE DownloadClients SET RemoveCompletedDownloads = (CASE WHEN Implementation IN (\"RTorrent\", \"Flood\") THEN 0 ELSE ? END), RemoveFailedDownloads = ?")) { updateClientCmd.AddParameter(removeCompletedDownloads ? 1 : 0); updateClientCmd.AddParameter(removeFailedDownloads ? 1 : 0); diff --git a/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs b/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs index a9cf03b22..a613146c3 100644 --- a/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs +++ b/src/NzbDrone.Core/Download/Clients/Flood/Flood.cs @@ -18,8 +18,10 @@ namespace NzbDrone.Core.Download.Clients.Flood public class Flood : TorrentClientBase { private readonly IFloodProxy _proxy; + private readonly IDownloadSeedConfigProvider _downloadSeedConfigProvider; public Flood(IFloodProxy proxy, + IDownloadSeedConfigProvider downloadSeedConfigProvider, ITorrentFileInfoReader torrentFileInfoReader, IHttpClient httpClient, IConfigService configService, @@ -29,6 +31,7 @@ public Flood(IFloodProxy proxy, : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; + _downloadSeedConfigProvider = downloadSeedConfigProvider; } private static IEnumerable HandleTags(RemoteEpisode remoteEpisode, FloodSettings settings) @@ -77,7 +80,7 @@ private static IEnumerable HandleTags(RemoteEpisode remoteEpisode, Flood } public override string Name => "Flood"; - public override ProviderMessage Message => new ProviderMessage("Sonarr is unable to remove torrents that have finished seeding when using Flood", ProviderMessageType.Warning); + public override ProviderMessage Message => new ProviderMessage("Sonarr will handle automatic removal of torrents based on the current seed criteria in Settings -> Indexers", ProviderMessageType.Info); protected override string AddFromTorrentFile(RemoteEpisode remoteEpisode, string hash, string filename, byte[] fileContent) { @@ -119,6 +122,8 @@ public override IEnumerable GetItems() TotalSize = properties.SizeBytes, SeedRatio = properties.Ratio, Message = properties.Message, + CanMoveFiles = false, + CanBeRemoved = false, }; if (properties.Eta > 0) @@ -143,7 +148,28 @@ public override IEnumerable GetItems() item.Status = DownloadItemStatus.Paused; } - item.CanMoveFiles = item.CanBeRemoved = false; + if (item.Status == DownloadItemStatus.Completed) + { + // Grab cached seedConfig + var seedConfig = _downloadSeedConfigProvider.GetSeedConfiguration(item.DownloadId); + + if (seedConfig != null) + { + if (item.SeedRatio >= seedConfig.Ratio) + { + // Check if seed ratio reached + item.CanMoveFiles = item.CanBeRemoved = true; + } + else if (properties.DateFinished != null && properties.DateFinished > 0) + { + // Check if seed time reached + if ((DateTimeOffset.Now - DateTimeOffset.FromUnixTimeSeconds(properties.DateFinished)) >= seedConfig.SeedTime) + { + item.CanMoveFiles = item.CanBeRemoved = true; + } + } + } + } items.Add(item); } diff --git a/src/NzbDrone.Core/Download/Clients/Flood/Types/Torrent.cs b/src/NzbDrone.Core/Download/Clients/Flood/Types/Torrent.cs index 3f3500307..92ac1d1ab 100644 --- a/src/NzbDrone.Core/Download/Clients/Flood/Types/Torrent.cs +++ b/src/NzbDrone.Core/Download/Clients/Flood/Types/Torrent.cs @@ -31,5 +31,9 @@ public sealed class Torrent [JsonProperty(PropertyName = "tags")] public List Tags { get; set; } + + // added in Flood 4.5 + [JsonProperty(PropertyName = "dateFinished")] + public long? DateFinished { get; set; } } }