fixed Deluge processing for changing category

This commit is contained in:
Flaminel
2025-03-25 22:15:04 +02:00
parent 7b95ec579c
commit 60e838cba7
@@ -217,24 +217,30 @@ public class DelugeService : DownloadService, IDelugeService
.ToList(); .ToList();
} }
public override List<object>? FilterDownloadsToBeCleanedAsync(List<object>? downloads, List<CleanCategory> categories) public override List<object>? FilterDownloadsToBeCleanedAsync(List<object>? downloads, List<CleanCategory> categories) =>
{ downloads
return downloads
?.Cast<TorrentStatus>() ?.Cast<TorrentStatus>()
.Where(x => categories.Any(cat => cat.Name.Equals(x.Label, StringComparison.InvariantCultureIgnoreCase))) .Where(x => categories.Any(cat => cat.Name.Equals(x.Label, StringComparison.InvariantCultureIgnoreCase)))
.Cast<object>() .Cast<object>()
.ToList(); .ToList();
}
public override List<object>? FilterDownloadsToChangeCategoryAsync(List<object>? downloads, List<string> categories) public override List<object>? FilterDownloadsToChangeCategoryAsync(List<object>? downloads, List<string> categories) =>
{ downloads
throw new NotImplementedException(); ?.Cast<TorrentStatus>()
} .Where(x => !string.IsNullOrEmpty(x.Hash))
.Where(x => categories.Any(cat => cat.Equals(x.Label, StringComparison.InvariantCultureIgnoreCase)))
.Cast<object>()
.ToList();
/// <inheritdoc/> /// <inheritdoc/>
public override async Task CleanDownloadsAsync(List<object> downloads, List<CleanCategory> categoriesToClean, HashSet<string> excludedHashes, public override async Task CleanDownloadsAsync(List<object>? downloads, List<CleanCategory> categoriesToClean, HashSet<string> excludedHashes,
IReadOnlyList<string> ignoredDownloads) IReadOnlyList<string> ignoredDownloads)
{ {
if (downloads?.Count is null or 0)
{
return;
}
foreach (TorrentStatus download in downloads) foreach (TorrentStatus download in downloads)
{ {
if (string.IsNullOrEmpty(download.Hash)) if (string.IsNullOrEmpty(download.Hash))
@@ -242,6 +248,12 @@ public class DelugeService : DownloadService, IDelugeService
continue; continue;
} }
if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase)))
{
_logger.LogDebug("skip | download is used by an arr | {name}", download.Name);
continue;
}
if (ignoredDownloads.Count > 0 && download.ShouldIgnore(ignoredDownloads)) if (ignoredDownloads.Count > 0 && download.ShouldIgnore(ignoredDownloads))
{ {
_logger.LogInformation("skip | download is ignored | {name}", download.Name); _logger.LogInformation("skip | download is ignored | {name}", download.Name);
@@ -256,12 +268,6 @@ public class DelugeService : DownloadService, IDelugeService
continue; continue;
} }
if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase)))
{
_logger.LogDebug("skip | download is used by an arr | {name}", download.Name);
continue;
}
if (!_downloadCleanerConfig.DeletePrivate && download.Private) if (!_downloadCleanerConfig.DeletePrivate && download.Private)
{ {
_logger.LogDebug("skip | download is private | {name}", download.Name); _logger.LogDebug("skip | download is private | {name}", download.Name);
@@ -312,105 +318,77 @@ public class DelugeService : DownloadService, IDelugeService
return; return;
} }
throw new NotImplementedException(); if (!string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir))
{
_hardLinkFileService.PopulateFileCounts(_downloadCleanerConfig.UnlinkedIgnoredRootDir);
}
// if (_downloadCleanerConfig.NoHardLinksIgnoreRootDir) foreach (TorrentStatus download in downloads.Cast<TorrentStatus>())
// { {
// downloads if (string.IsNullOrEmpty(download.Hash) || string.IsNullOrEmpty(download.Name) || string.IsNullOrEmpty(download.Label))
// .Cast<TorrentStatus>() {
// .Select(x => continue;
// { }
// string? firstDir = GetRootWithFirstDirectory(x.DownloadPath);
// if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase)))
// if (string.IsNullOrEmpty(firstDir)) {
// { _logger.LogDebug("skip | download is used by an arr | {name}", download.Name);
// return string.Empty; continue;
// } }
//
// if (firstDir == Path.GetPathRoot(x.DownloadPath)) if (ignoredDownloads.Count > 0 && download.ShouldIgnore(ignoredDownloads))
// { {
// return string.Empty; _logger.LogInformation("skip | download is ignored | {name}", download.Name);
// } continue;
// }
// return firstDir;
// }) ContextProvider.Set("downloadName", download.Name);
// .Where(x => !string.IsNullOrEmpty(x)) ContextProvider.Set("hash", download.Hash);
// .Distinct()
// .ToList() DelugeContents? contents = null;
// .ForEach(x => try
// { {
// _logger.LogTrace("populating file counts from {dir}", x); contents = await _client.GetTorrentFiles(download.Hash);
// }
// if (!Directory.Exists(x)) catch (Exception exception)
// { {
// throw new ValidationException($"directory \"{x}\" does not exist"); _logger.LogDebug(exception, "failed to find torrent files for {name}", download.Name);
// } continue;
// }
// _hardLinkFileService.PopulateFileCounts(x);
// }); bool hasHardlinks = false;
// }
// ProcessFiles(contents?.Contents, (_, file) =>
// foreach (TorrentStatus download in downloads.Cast<TorrentStatus>()) {
// { long hardlinkCount = _hardLinkFileService.GetHardLinkCount(file.Path, !string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir));
// if (string.IsNullOrEmpty(download.Hash))
// { if (hardlinkCount < 0)
// _logger.LogDebug("skip | download hash is null for {name}", download.Name); {
// continue; _logger.LogDebug("skip | could not get file properties | {name}", download.Name);
// } hasHardlinks = true;
// return;
// if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase))) }
// {
// _logger.LogDebug("skip | download is used by an arr | {name}", download.Name); if (hardlinkCount > 0)
// continue; {
// } hasHardlinks = true;
// }
// ContextProvider.Set("downloadName", download.Name); });
// ContextProvider.Set("hash", download.Hash);
// if (hasHardlinks)
// DelugeContents? contents = null; {
// try _logger.LogDebug("skip | download has hardlinks | {name}", download.Name);
// { continue;
// contents = await _client.GetTorrentFiles(download.Hash); }
// }
// catch (Exception exception) await _dryRunInterceptor.InterceptAsync(ChangeLabel, download.Hash, _downloadCleanerConfig.UnlinkedTargetCategory);
// {
// _logger.LogDebug(exception, "failed to find torrent files for {name}", download.Name); _logger.LogInformation("category changed for {name}", download.Name);
// continue;
// } await _notifier.NotifyCategoryChanged(download.Label, _downloadCleanerConfig.UnlinkedTargetCategory);
//
// bool hasHardlinks = false; download.Label = _downloadCleanerConfig.UnlinkedTargetCategory;
// }
// ProcessFiles(contents?.Contents, (name, file) =>
// {
// string filePath = Path.Combine(download.DownloadPath, file.Path);
//
// long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, _downloadCleanerConfig.NoHardLinksIgnoreRootDir);
//
// if (hardlinkCount < 0)
// {
// _logger.LogDebug("skip | could not get file properties | {name}", download.Name);
// hasHardlinks = true;
// return;
// }
//
// if (hardlinkCount > 0)
// {
// hasHardlinks = true;
// }
// });
//
// if (hasHardlinks)
// {
// _logger.LogDebug("skip | download has hardlinks | {name}", download.Name);
// continue;
// }
//
// await _dryRunInterceptor.InterceptAsync(ChangeLabel, download.Hash, _downloadCleanerConfig.NoHardLinksCategory);
//
// _logger.LogInformation("category changed for {name}", download.Name);
//
// await _notifier.NotifyCategoryChanged(download.Label, _downloadCleanerConfig.NoHardLinksCategory);
// }
} }
/// <inheritdoc/> /// <inheritdoc/>