mirror of
https://github.com/Sonarr/Sonarr
synced 2026-05-08 13:01:10 +02:00
Stop tracking downloads after they're removed from the download client
This commit is contained in:
parent
5c5b53d341
commit
e38a2af1ad
4 changed files with 9 additions and 14 deletions
|
|
@ -81,8 +81,8 @@ public override IEnumerable<DownloadClientItem> GetItems()
|
|||
{
|
||||
var firstFile = torrent.Files?.FirstOrDefault();
|
||||
|
||||
// skip metadata download
|
||||
if (firstFile?.Path?.Contains("[METADATA]") == true)
|
||||
// skip metadata download or if the torrent is already removed
|
||||
if (firstFile?.Path?.Contains("[METADATA]") == true || torrent.Status == "removed")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -120,9 +120,6 @@ public override IEnumerable<DownloadClientItem> GetItems()
|
|||
case "complete":
|
||||
status = DownloadItemStatus.Completed;
|
||||
break;
|
||||
case "removed":
|
||||
status = DownloadItemStatus.Failed;
|
||||
break;
|
||||
}
|
||||
|
||||
_logger.Trace($"- aria2 getstatus hash:'{torrent.InfoHash}' gid:'{torrent.Gid}' status:'{status}' total:{totalLength} completed:'{completedLength}'");
|
||||
|
|
@ -139,7 +136,6 @@ public override IEnumerable<DownloadClientItem> GetItems()
|
|||
OutputPath = outputPath,
|
||||
RemainingSize = totalLength - completedLength,
|
||||
RemainingTime = downloadSpeed == 0 ? (TimeSpan?)null : new TimeSpan(0, 0, (int)((totalLength - completedLength) / downloadSpeed)),
|
||||
Removed = torrent.Status == "removed",
|
||||
SeedRatio = totalLength > 0 ? (double)uploadedLength / totalLength : 0,
|
||||
Status = status,
|
||||
Title = title,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ public class DownloadClientItem
|
|||
public bool IsEncrypted { get; set; }
|
||||
public bool CanMoveFiles { get; set; }
|
||||
public bool CanBeRemoved { get; set; }
|
||||
public bool Removed { get; set; }
|
||||
|
||||
public DownloadClientItem Clone()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,14 +12,17 @@ public class DownloadEventHub : IHandle<DownloadFailedEvent>,
|
|||
{
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IProvideDownloadClient _downloadClientProvider;
|
||||
private readonly ITrackedDownloadService _trackedDownloadService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public DownloadEventHub(IConfigService configService,
|
||||
IProvideDownloadClient downloadClientProvider,
|
||||
ITrackedDownloadService trackedDownloadService,
|
||||
Logger logger)
|
||||
{
|
||||
_configService = configService;
|
||||
_downloadClientProvider = downloadClientProvider;
|
||||
_trackedDownloadService = trackedDownloadService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +31,6 @@ public void Handle(DownloadFailedEvent message)
|
|||
var trackedDownload = message.TrackedDownload;
|
||||
|
||||
if (trackedDownload == null ||
|
||||
message.TrackedDownload.DownloadItem.Removed ||
|
||||
!trackedDownload.DownloadItem.CanBeRemoved)
|
||||
{
|
||||
return;
|
||||
|
|
@ -53,8 +55,7 @@ public void Handle(DownloadCompletedEvent message)
|
|||
|
||||
MarkItemAsImported(trackedDownload, downloadClient);
|
||||
|
||||
if (trackedDownload.DownloadItem.Removed ||
|
||||
!trackedDownload.DownloadItem.CanBeRemoved ||
|
||||
if (!trackedDownload.DownloadItem.CanBeRemoved ||
|
||||
trackedDownload.DownloadItem.Status == DownloadItemStatus.Downloading)
|
||||
{
|
||||
return;
|
||||
|
|
@ -74,8 +75,7 @@ public void Handle(DownloadCanBeRemovedEvent message)
|
|||
var downloadClient = _downloadClientProvider.Get(trackedDownload.DownloadClient);
|
||||
var definition = downloadClient.Definition as DownloadClientDefinition;
|
||||
|
||||
if (trackedDownload.DownloadItem.Removed ||
|
||||
!trackedDownload.DownloadItem.CanBeRemoved ||
|
||||
if (!trackedDownload.DownloadItem.CanBeRemoved ||
|
||||
!definition.RemoveCompletedDownloads)
|
||||
{
|
||||
return;
|
||||
|
|
@ -90,7 +90,7 @@ private void RemoveFromDownloadClient(TrackedDownload trackedDownload, IDownload
|
|||
{
|
||||
_logger.Debug("[{0}] Removing download from {1} history", trackedDownload.DownloadItem.Title, trackedDownload.DownloadItem.DownloadClientInfo.Name);
|
||||
downloadClient.RemoveItem(trackedDownload.DownloadItem, true);
|
||||
trackedDownload.DownloadItem.Removed = true;
|
||||
_trackedDownloadService.StopTracking(trackedDownload.DownloadItem.DownloadId);
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public DownloadProcessingService(IConfigService configService,
|
|||
private void RemoveCompletedDownloads()
|
||||
{
|
||||
var trackedDownloads = _trackedDownloadService.GetTrackedDownloads()
|
||||
.Where(t => !t.DownloadItem.Removed && t.DownloadItem.CanBeRemoved && t.State == TrackedDownloadState.Imported)
|
||||
.Where(t => t.DownloadItem.CanBeRemoved && t.State == TrackedDownloadState.Imported)
|
||||
.ToList();
|
||||
|
||||
foreach (var trackedDownload in trackedDownloads)
|
||||
|
|
|
|||
Loading…
Reference in a new issue