From fd3dd1ab7dc86cd9e231fa432cc8d2772d5a4bad Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 23 May 2024 06:42:16 -0700 Subject: [PATCH] New: Genres and Images for Webhooks and Notifiarr Closes #6822 --- .../Notifications/Notifiarr/Notifiarr.cs | 5 ++-- .../Notifications/Webhook/Webhook.cs | 5 ++-- .../Notifications/Webhook/WebhookBase.cs | 26 +++++++++++++------ .../Notifications/Webhook/WebhookImage.cs | 18 +++++++++++++ .../Notifications/Webhook/WebhookSeries.cs | 5 ++++ 5 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookImage.cs diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs index 96251eb32..498a4724e 100644 --- a/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs +++ b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs @@ -3,6 +3,7 @@ using FluentValidation.Results; using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; using NzbDrone.Core.Localization; +using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Notifications.Webhook; using NzbDrone.Core.Tags; @@ -15,8 +16,8 @@ namespace NzbDrone.Core.Notifications.Notifiarr { private readonly INotifiarrProxy _proxy; - public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService, ITagRepository tagRepository) - : base(configFileProvider, configService, localizationService, tagRepository) + public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService, ITagRepository tagRepository, IMapCoversToLocal mediaCoverService) + : base(configFileProvider, configService, localizationService, tagRepository, mediaCoverService) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs index 7d0e84478..1e09e8e13 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs @@ -3,6 +3,7 @@ using FluentValidation.Results; using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; using NzbDrone.Core.Localization; +using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tags; using NzbDrone.Core.Tv; @@ -14,8 +15,8 @@ namespace NzbDrone.Core.Notifications.Webhook { private readonly IWebhookProxy _proxy; - public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService, ITagRepository tagRepository) - : base(configFileProvider, configService, localizationService, tagRepository) + public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService, ITagRepository tagRepository, IMapCoversToLocal mediaCoverService) + : base(configFileProvider, configService, localizationService, tagRepository, mediaCoverService) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs index c02fb5828..d87e92a42 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs @@ -4,6 +4,7 @@ using System.Linq; using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; using NzbDrone.Core.Localization; +using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tags; using NzbDrone.Core.Tv; @@ -17,13 +18,15 @@ namespace NzbDrone.Core.Notifications.Webhook private readonly IConfigService _configService; protected readonly ILocalizationService _localizationService; private readonly ITagRepository _tagRepository; + private readonly IMapCoversToLocal _mediaCoverService; - protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService, ITagRepository tagRepository) + protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService, ITagRepository tagRepository, IMapCoversToLocal mediaCoverService) { _configFileProvider = configFileProvider; _configService = configService; _localizationService = localizationService; _tagRepository = tagRepository; + _mediaCoverService = mediaCoverService; } protected WebhookGrabPayload BuildOnGrabPayload(GrabMessage message) @@ -36,7 +39,7 @@ namespace NzbDrone.Core.Notifications.Webhook EventType = WebhookEventType.Grab, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Series = new WebhookSeries(message.Series, GetTagLabels(message.Series)), + Series = GetSeries(message.Series), Episodes = remoteEpisode.Episodes.ConvertAll(x => new WebhookEpisode(x)), Release = new WebhookRelease(quality, remoteEpisode), DownloadClient = message.DownloadClientName, @@ -55,7 +58,7 @@ namespace NzbDrone.Core.Notifications.Webhook EventType = WebhookEventType.Download, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Series = new WebhookSeries(message.Series, GetTagLabels(message.Series)), + Series = GetSeries(message.Series), Episodes = episodeFile.Episodes.Value.ConvertAll(x => new WebhookEpisode(x)), EpisodeFile = new WebhookEpisodeFile(episodeFile), Release = new WebhookGrabbedRelease(message.Release), @@ -85,7 +88,7 @@ namespace NzbDrone.Core.Notifications.Webhook EventType = WebhookEventType.EpisodeFileDelete, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Series = new WebhookSeries(deleteMessage.Series, GetTagLabels(deleteMessage.Series)), + Series = GetSeries(deleteMessage.Series), Episodes = deleteMessage.EpisodeFile.Episodes.Value.ConvertAll(x => new WebhookEpisode(x)), EpisodeFile = new WebhookEpisodeFile(deleteMessage.EpisodeFile), DeleteReason = deleteMessage.Reason @@ -99,7 +102,7 @@ namespace NzbDrone.Core.Notifications.Webhook EventType = WebhookEventType.SeriesAdd, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Series = new WebhookSeries(addMessage.Series, GetTagLabels(addMessage.Series)), + Series = GetSeries(addMessage.Series), }; } @@ -110,7 +113,7 @@ namespace NzbDrone.Core.Notifications.Webhook EventType = WebhookEventType.SeriesDelete, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Series = new WebhookSeries(deleteMessage.Series, GetTagLabels(deleteMessage.Series)), + Series = GetSeries(deleteMessage.Series), DeletedFiles = deleteMessage.DeletedFiles }; } @@ -122,7 +125,7 @@ namespace NzbDrone.Core.Notifications.Webhook EventType = WebhookEventType.Rename, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Series = new WebhookSeries(series, GetTagLabels(series)), + Series = GetSeries(series), RenamedEpisodeFiles = renamedFiles.ConvertAll(x => new WebhookRenamedEpisodeFile(x)) }; } @@ -175,7 +178,7 @@ namespace NzbDrone.Core.Notifications.Webhook EventType = WebhookEventType.ManualInteractionRequired, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Series = new WebhookSeries(message.Series, GetTagLabels(message.Series)), + Series = GetSeries(message.Series), Episodes = remoteEpisode.Episodes.ConvertAll(x => new WebhookEpisode(x)), DownloadInfo = new WebhookDownloadClientItem(quality, message.TrackedDownload.DownloadItem), DownloadClient = message.DownloadClientInfo?.Name, @@ -216,6 +219,13 @@ namespace NzbDrone.Core.Notifications.Webhook }; } + private WebhookSeries GetSeries(Series series) + { + _mediaCoverService.ConvertToLocalUrls(series.Id, series.Images); + + return new WebhookSeries(series, GetTagLabels(series)); + } + private List GetTagLabels(Series series) { return _tagRepository.GetTags(series.Tags) diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookImage.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookImage.cs new file mode 100644 index 000000000..87f511dc1 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookImage.cs @@ -0,0 +1,18 @@ +using NzbDrone.Core.MediaCover; + +namespace NzbDrone.Core.Notifications.Webhook +{ + public class WebhookImage + { + public MediaCoverTypes CoverType { get; set; } + public string Url { get; set; } + public string RemoteUrl { get; set; } + + public WebhookImage(MediaCover.MediaCover image) + { + CoverType = image.CoverType; + RemoteUrl = image.RemoteUrl; + Url = image.Url; + } + } +} diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookSeries.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookSeries.cs index 57200fb40..1177f2065 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookSeries.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookSeries.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Notifications.Webhook @@ -14,6 +15,8 @@ namespace NzbDrone.Core.Notifications.Webhook public string ImdbId { get; set; } public SeriesTypes Type { get; set; } public int Year { get; set; } + public List Genres { get; set; } + public List Images { get; set; } public List Tags { get; set; } public WebhookSeries() @@ -31,6 +34,8 @@ namespace NzbDrone.Core.Notifications.Webhook ImdbId = series.ImdbId; Type = series.SeriesType; Year = series.Year; + Genres = series.Genres; + Images = series.Images.Select(i => new WebhookImage(i)).ToList(); Tags = tags; } }