From dfb00d9bb1cf0bfb5a98d5bfdde6fde4aa20d727 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 12 Aug 2023 12:07:17 +0300 Subject: [PATCH] Fixed: Ensure grab notifications are sent according to tags requirements --- src/NzbDrone.Core/Download/DownloadService.cs | 3 +++ .../Indexers/Events/IndexerDownloadEvent.cs | 1 + .../Notifications/NotificationService.cs | 27 ++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/Download/DownloadService.cs b/src/NzbDrone.Core/Download/DownloadService.cs index d5e6368f1..675ab3b8e 100644 --- a/src/NzbDrone.Core/Download/DownloadService.cs +++ b/src/NzbDrone.Core/Download/DownloadService.cs @@ -74,6 +74,7 @@ private async Task SendReportToClient(ReleaseInfo release, string source, string DownloadClientId = downloadClient.Definition.Id, DownloadClientName = downloadClient.Definition.Name, Redirect = redirect, + Indexer = indexer, GrabTrigger = source == "Prowlarr" ? GrabTrigger.Manual : GrabTrigger.Api }; @@ -152,6 +153,7 @@ public async Task DownloadReport(string link, int indexerId, string sour var grabEvent = new IndexerDownloadEvent(release, success, source, host, release.Title, release.DownloadUrl) { + Indexer = indexer, GrabTrigger = source == "Prowlarr" ? GrabTrigger.Manual : GrabTrigger.Api }; @@ -204,6 +206,7 @@ public void RecordRedirect(string link, int indexerId, string source, string hos var grabEvent = new IndexerDownloadEvent(release, true, source, host, release.Title, release.DownloadUrl) { Redirect = true, + Indexer = indexer, GrabTrigger = source == "Prowlarr" ? GrabTrigger.Manual : GrabTrigger.Api }; diff --git a/src/NzbDrone.Core/Indexers/Events/IndexerDownloadEvent.cs b/src/NzbDrone.Core/Indexers/Events/IndexerDownloadEvent.cs index ae1495dd0..43bf8cd60 100644 --- a/src/NzbDrone.Core/Indexers/Events/IndexerDownloadEvent.cs +++ b/src/NzbDrone.Core/Indexers/Events/IndexerDownloadEvent.cs @@ -16,6 +16,7 @@ public class IndexerDownloadEvent : IEvent public string DownloadClient { get; set; } public string DownloadClientName { get; set; } public string DownloadId { get; set; } + public IIndexer Indexer { get; set; } public GrabTrigger GrabTrigger { get; set; } public IndexerDownloadEvent(ReleaseInfo release, bool successful, string source, string host, string title, string url) diff --git a/src/NzbDrone.Core/Notifications/NotificationService.cs b/src/NzbDrone.Core/Notifications/NotificationService.cs index 9ee85d0a0..8f5610975 100644 --- a/src/NzbDrone.Core/Notifications/NotificationService.cs +++ b/src/NzbDrone.Core/Notifications/NotificationService.cs @@ -1,10 +1,13 @@ using System; +using System.Linq; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Core.HealthCheck; +using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers.Events; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Update.History.Events; namespace NzbDrone.Core.Notifications @@ -185,7 +188,8 @@ public void Handle(IndexerDownloadEvent message) { try { - if (ShouldHandleOnGrab(grabMessage, ((NotificationDefinition)notification.Definition).IncludeManualGrabs)) + if (ShouldHandleIndexer(notification.Definition, (IndexerDefinition)message.Indexer.Definition) && + ShouldHandleOnGrab(grabMessage, ((NotificationDefinition)notification.Definition).IncludeManualGrabs)) { notification.OnGrab(grabMessage); } @@ -196,5 +200,26 @@ public void Handle(IndexerDownloadEvent message) } } } + + private bool ShouldHandleIndexer(ProviderDefinition definition, ProviderDefinition indexer) + { + if (definition.Tags.Empty()) + { + _logger.Debug("No tags set for this notification."); + + return true; + } + + if (definition.Tags.Intersect(indexer.Tags).Any()) + { + _logger.Debug("Notification and indexer have one or more intersecting tags."); + + return true; + } + + _logger.Debug("{0} does not have any intersecting tags with {1}. Notification will not be sent.", definition.Name, indexer.Name); + + return false; + } } }