diff --git a/code/Common/Configuration/DownloadCleaner/DownloadCleanerConfig.cs b/code/Common/Configuration/DownloadCleaner/DownloadCleanerConfig.cs index cfede35c..25ab7b35 100644 --- a/code/Common/Configuration/DownloadCleaner/DownloadCleanerConfig.cs +++ b/code/Common/Configuration/DownloadCleaner/DownloadCleanerConfig.cs @@ -33,11 +33,6 @@ public sealed record DownloadCleanerConfig : IJobConfig, IIgnoredDownloadsConfig return; } - if (Categories?.Count is null or 0) - { - throw new ValidationException("no categories configured"); - } - if (Categories?.GroupBy(x => x.Name).Any(x => x.Count() > 1) is true) { throw new ValidationException("duplicated clean categories found"); diff --git a/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs b/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs index cb486744..4aad682e 100644 --- a/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs +++ b/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs @@ -58,9 +58,12 @@ public sealed class DownloadCleaner : GenericHandler return; } - if (_config.Categories?.Count is null or 0) + bool isUnlinkedEnabled = !string.IsNullOrEmpty(_config.UnlinkedTargetCategory) && _config.UnlinkedCategories?.Count > 0; + bool isCleaningEnabled = _config.Categories?.Count > 0; + + if (!isUnlinkedEnabled && !isCleaningEnabled) { - _logger.LogWarning("no categories configured"); + _logger.LogWarning("{name} is not configured properly", nameof(DownloadCleaner)); return; } @@ -68,9 +71,18 @@ public sealed class DownloadCleaner : GenericHandler await _downloadService.LoginAsync(); List? downloads = await _downloadService.GetSeedingDownloads(); - List? downloadsToChangeCategory = null; + + if (downloads?.Count is null or 0) + { + _logger.LogDebug("no seeding downloads found"); + return; + } - if (!string.IsNullOrEmpty(_config.UnlinkedTargetCategory) && _config.UnlinkedCategories?.Count > 0) + _logger.LogTrace("found {count} seeding downloads", downloads.Count); + + List? downloadsToChangeCategory = null; + + if (isUnlinkedEnabled) { if (!_hardLinkCategoryCreated) { @@ -89,17 +101,27 @@ public sealed class DownloadCleaner : GenericHandler await ProcessArrConfigAsync(_sonarrConfig, InstanceType.Sonarr, true); await ProcessArrConfigAsync(_radarrConfig, InstanceType.Radarr, true); await ProcessArrConfigAsync(_lidarrConfig, InstanceType.Lidarr, true); + + if (isUnlinkedEnabled) + { + _logger.LogTrace("found {count} potential downloads to change category", downloadsToChangeCategory?.Count); + await _downloadService.ChangeCategoryForNoHardLinksAsync(downloadsToChangeCategory, _excludedHashes, ignoredDownloads); + _logger.LogTrace("finished changing category"); + } - _logger.LogTrace("looking for downloads to change category"); - await _downloadService.ChangeCategoryForNoHardLinksAsync(downloadsToChangeCategory, _excludedHashes, ignoredDownloads); + if (_config.Categories?.Count is null or 0) + { + return; + } List? downloadsToClean = _downloadService.FilterDownloadsToBeCleanedAsync(downloads, _config.Categories); // release unused objects downloads = null; - - _logger.LogTrace("looking for downloads to clean"); + + _logger.LogTrace("found {count} potential downloads to clean", downloadsToClean?.Count); await _downloadService.CleanDownloadsAsync(downloadsToClean, _config.Categories, _excludedHashes, ignoredDownloads); + _logger.LogTrace("finished cleaning downloads"); } protected override async Task ProcessInstanceAsync(ArrInstance instance, InstanceType instanceType) diff --git a/docs/docs/configuration/examples/1_docker.mdx b/docs/docs/configuration/examples/1_docker.mdx index 763a93c7..85d9d17c 100644 --- a/docs/docs/configuration/examples/1_docker.mdx +++ b/docs/docs/configuration/examples/1_docker.mdx @@ -12,8 +12,12 @@ services: image: ghcr.io/flmorg/cleanuperr:latest restart: unless-stopped volumes: + # if you want persistent logs - ./cleanuperr/logs:/var/logs + # if you want to ignore certain downloads from being processed - ./cleanuperr/ignored.txt:/ignored.txt + # if you're using cross-seed and the hardlinks functionality + - ./downloads:/downloads environment: # general settings - TZ=America/New_York diff --git a/docs/src/components/configuration/download-cleaner/DownloadCleanerHardlinksSettings.tsx b/docs/src/components/configuration/download-cleaner/DownloadCleanerHardlinksSettings.tsx index cca58352..6eafa50f 100644 --- a/docs/src/components/configuration/download-cleaner/DownloadCleanerHardlinksSettings.tsx +++ b/docs/src/components/configuration/download-cleaner/DownloadCleanerHardlinksSettings.tsx @@ -30,11 +30,17 @@ const settings: EnvVarProps[] = [ title: "Multiple patterns can be specified using incrementing numbers starting from 0.", content: `DOWNLOADCLEANER__UNLINKED_CATEGORIES__0=tv-sonarr DOWNLOADCLEANER__UNLINKED_CATEGORIES__1=radarr` - } + }, ], type: "text", defaultValue: "Empty", required: false, + notes: [ + "The category name must match the category that was set in the *arr.", + "For qBittorrent, the category name is the name of the download category.", + "For Deluge, the category name is the name of the label.", + "For Transmission, the category name is the last directory from the save location.", + ], } ];