Stop tracking downloads after they're removed from the download client

This commit is contained in:
realzombee 2026-04-21 00:53:36 +01:00 committed by GitHub
parent 5c5b53d341
commit e38a2af1ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 14 deletions

View file

@ -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,

View file

@ -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()
{

View file

@ -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)
{

View file

@ -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)