diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index ff5a71fd3..3fd5008cb 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -70,7 +70,8 @@ namespace NzbDrone.Core.Download return; } - var historyItem = _historyService.MostRecentForDownloadId(trackedDownload.DownloadItem.DownloadId); + var grabbedHistories = _historyService.FindByDownloadId(trackedDownload.DownloadItem.DownloadId).Where(h => h.EventType == EpisodeHistoryEventType.Grabbed).ToList(); + var historyItem = grabbedHistories.MaxBy(h => h.Date); if (historyItem == null && trackedDownload.DownloadItem.Category.IsNullOrWhiteSpace()) { @@ -110,7 +111,9 @@ namespace NzbDrone.Core.Download { trackedDownload.HasNotifiedManualInteractionRequired = true; - var manualInteractionEvent = new ManualInteractionRequiredEvent(trackedDownload); + var releaseInfo = new GrabbedReleaseInfo(grabbedHistories); + var manualInteractionEvent = new ManualInteractionRequiredEvent(trackedDownload, releaseInfo); + _eventAggregator.PublishEvent(manualInteractionEvent); } diff --git a/src/NzbDrone.Core/Download/ManualInteractionRequiredEvent.cs b/src/NzbDrone.Core/Download/ManualInteractionRequiredEvent.cs index c7fb39b8e..d74e23bcb 100644 --- a/src/NzbDrone.Core/Download/ManualInteractionRequiredEvent.cs +++ b/src/NzbDrone.Core/Download/ManualInteractionRequiredEvent.cs @@ -8,11 +8,13 @@ namespace NzbDrone.Core.Download { public RemoteEpisode Episode { get; private set; } public TrackedDownload TrackedDownload { get; private set; } + public GrabbedReleaseInfo Release { get; private set; } - public ManualInteractionRequiredEvent(TrackedDownload trackedDownload) + public ManualInteractionRequiredEvent(TrackedDownload trackedDownload, GrabbedReleaseInfo release) { TrackedDownload = trackedDownload; Episode = trackedDownload.RemoteEpisode; + Release = release; } } } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseInfo.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseInfo.cs index b35f3ea14..8456c7838 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseInfo.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateReleaseInfo.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using NzbDrone.Common.Extensions; using NzbDrone.Core.Download; using NzbDrone.Core.History; @@ -31,20 +32,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators return localEpisode; } - var episodeIds = grabbedHistories.Select(h => h.EpisodeId).Distinct().ToList(); - var grabbedHistory = grabbedHistories.First(); - var releaseInfo = new GrabbedReleaseInfo(); - - grabbedHistory.Data.TryGetValue("indexer", out var indexer); - grabbedHistory.Data.TryGetValue("size", out var sizeString); - long.TryParse(sizeString, out var size); - - releaseInfo.Title = grabbedHistory.SourceTitle; - releaseInfo.Indexer = indexer; - releaseInfo.Size = size; - releaseInfo.EpisodeIds = episodeIds; - - localEpisode.Release = releaseInfo; + localEpisode.Release = new GrabbedReleaseInfo(grabbedHistories); return localEpisode; } diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs index e48269e2b..cfb7b1756 100644 --- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs +++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs @@ -308,7 +308,7 @@ namespace NzbDrone.Core.Notifications.CustomScript var series = message.Series; var environmentVariables = new StringDictionary(); - environmentVariables.Add("Sonarr_EventType", "Download"); + environmentVariables.Add("Sonarr_EventType", "ManualInteractionRequired"); environmentVariables.Add("Sonarr_InstanceName", _configFileProvider.InstanceName); environmentVariables.Add("Sonarr_ApplicationUrl", _configService.ApplicationUrl); environmentVariables.Add("Sonarr_Series_Id", series.Id.ToString()); diff --git a/src/NzbDrone.Core/Notifications/ManualInteractionRequiredMessage.cs b/src/NzbDrone.Core/Notifications/ManualInteractionRequiredMessage.cs index 84daa91f2..0d9f8f6b8 100644 --- a/src/NzbDrone.Core/Notifications/ManualInteractionRequiredMessage.cs +++ b/src/NzbDrone.Core/Notifications/ManualInteractionRequiredMessage.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Core.Notifications public string DownloadClientType { get; set; } public string DownloadClientName { get; set; } public string DownloadId { get; set; } + public GrabbedReleaseInfo Release { get; set; } public override string ToString() { diff --git a/src/NzbDrone.Core/Notifications/NotificationService.cs b/src/NzbDrone.Core/Notifications/NotificationService.cs index fb6958e66..2b8b7ded1 100644 --- a/src/NzbDrone.Core/Notifications/NotificationService.cs +++ b/src/NzbDrone.Core/Notifications/NotificationService.cs @@ -233,7 +233,8 @@ namespace NzbDrone.Core.Notifications TrackedDownload = message.TrackedDownload, DownloadClientType = message.TrackedDownload.DownloadItem.DownloadClientInfo.Type, DownloadClientName = message.TrackedDownload.DownloadItem.DownloadClientInfo.Name, - DownloadId = message.TrackedDownload.DownloadItem.DownloadId + DownloadId = message.TrackedDownload.DownloadItem.DownloadId, + Release = message.Release }; foreach (var notification in _notificationFactory.OnManualInteractionEnabled()) diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs index 7a007f82e..90baedeb8 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs @@ -165,13 +165,17 @@ namespace NzbDrone.Core.Notifications.Webhook return new WebhookManualInteractionPayload { - EventType = WebhookEventType.Grab, + EventType = WebhookEventType.ManualInteractionRequired, + InstanceName = _configFileProvider.InstanceName, + ApplicationUrl = _configService.ApplicationUrl, Series = new WebhookSeries(message.Series), Episodes = remoteEpisode.Episodes.ConvertAll(x => new WebhookEpisode(x)), DownloadInfo = new WebhookDownloadClientItem(quality, message.TrackedDownload.DownloadItem), DownloadClient = message.DownloadClientName, DownloadClientType = message.DownloadClientType, - DownloadId = message.DownloadId + DownloadId = message.DownloadId, + CustomFormatInfo = new WebhookCustomFormatInfo(remoteEpisode.CustomFormats, remoteEpisode.CustomFormatScore), + Release = new WebhookGrabbedRelease(message.Release) }; } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs index ce36841ec..b863a4ac9 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs @@ -17,6 +17,7 @@ namespace NzbDrone.Core.Notifications.Webhook EpisodeFileDelete, Health, ApplicationUpdate, - HealthRestored + HealthRestored, + ManualInteractionRequired } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookManualInteractionPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookManualInteractionPayload.cs index 179333001..fca226f4b 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookManualInteractionPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookManualInteractionPayload.cs @@ -10,5 +10,7 @@ namespace NzbDrone.Core.Notifications.Webhook public string DownloadClient { get; set; } public string DownloadClientType { get; set; } public string DownloadId { get; set; } + public WebhookCustomFormatInfo CustomFormatInfo { get; set; } + public WebhookGrabbedRelease Release { get; set; } } } diff --git a/src/NzbDrone.Core/Parser/Model/GrabbedReleaseInfo.cs b/src/NzbDrone.Core/Parser/Model/GrabbedReleaseInfo.cs index 869f8cdab..5ac847bea 100644 --- a/src/NzbDrone.Core/Parser/Model/GrabbedReleaseInfo.cs +++ b/src/NzbDrone.Core/Parser/Model/GrabbedReleaseInfo.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using System.Linq; +using NzbDrone.Core.History; namespace NzbDrone.Core.Parser.Model { @@ -9,5 +11,20 @@ namespace NzbDrone.Core.Parser.Model public long Size { get; set; } public List EpisodeIds { get; set; } + + public GrabbedReleaseInfo(List grabbedHistories) + { + var grabbedHistory = grabbedHistories.MaxBy(h => h.Date); + var episodeIds = grabbedHistories.Select(h => h.EpisodeId).Distinct().ToList(); + + grabbedHistory.Data.TryGetValue("indexer", out var indexer); + grabbedHistory.Data.TryGetValue("size", out var sizeString); + long.TryParse(sizeString, out var size); + + Title = grabbedHistory.SourceTitle; + Indexer = indexer; + Size = size; + EpisodeIds = episodeIds; + } } }