From fd1719e58c916f93439ee069ce60831bd2a80637 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 10 Dec 2024 19:22:58 -0800 Subject: [PATCH] Fixed: Artists without tags bypassing tags on Download Client (cherry picked from commit c0e264cfc520ee387bfc882c95a5822c655e0d9b) Fix typo about download clients comment (cherry picked from commit c39fb4fe6f0ed5e1dc2aa33f4455a4d0c760063b) Closes #5309 Closes #5318 --- .../Download/DownloadClientProvider.cs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/NzbDrone.Core/Download/DownloadClientProvider.cs b/src/NzbDrone.Core/Download/DownloadClientProvider.cs index c6d58b1b2..314ac783b 100644 --- a/src/NzbDrone.Core/Download/DownloadClientProvider.cs +++ b/src/NzbDrone.Core/Download/DownloadClientProvider.cs @@ -38,6 +38,10 @@ namespace NzbDrone.Core.Download public IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0, bool filterBlockedClients = false, HashSet tags = null) { + // Tags aren't required, but download clients with tags should not be picked unless there is at least one matching tag. + // Defaulting to an empty HashSet ensures this is always checked. + tags ??= new HashSet(); + var blockedProviders = new HashSet(_downloadClientStatusService.GetBlockedProviders().Select(v => v.ProviderId)); var availableProviders = _downloadClientFactory.GetAvailableProviders().Where(v => v.Protocol == downloadProtocol).ToList(); @@ -46,18 +50,15 @@ namespace NzbDrone.Core.Download return null; } - if (tags is { Count: > 0 }) - { - var matchingTagsClients = availableProviders.Where(i => i.Definition.Tags.Intersect(tags).Any()).ToList(); + var matchingTagsClients = availableProviders.Where(i => i.Definition.Tags.Intersect(tags).Any()).ToList(); - availableProviders = matchingTagsClients.Count > 0 ? - matchingTagsClients : - availableProviders.Where(i => i.Definition.Tags.Empty()).ToList(); + availableProviders = matchingTagsClients.Count > 0 ? + matchingTagsClients : + availableProviders.Where(i => i.Definition.Tags.Empty()).ToList(); - if (!availableProviders.Any()) - { - throw new DownloadClientUnavailableException("No download client was found without tags or a matching artist tag. Please check your settings."); - } + if (!availableProviders.Any()) + { + throw new DownloadClientUnavailableException("No download client was found without tags or a matching artist tag. Please check your settings."); } if (indexerId > 0)