Fixed: Ensure grab notifications are sent according to tags requirements

This commit is contained in:
Bogdan 2023-08-12 12:07:17 +03:00
parent f7727855b5
commit dfb00d9bb1
3 changed files with 30 additions and 1 deletions

View file

@ -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<byte[]> 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
};

View file

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

View file

@ -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;
}
}
}