From deac2bdf5c415a52f07b882387a1305ea5046cf5 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 1 Feb 2024 09:26:36 +0200 Subject: [PATCH] New: Tags field for Notifiarr and Webhook --- .../Notifications/Discord/Discord.cs | 2 +- .../Notifications/Notifiarr/Notifiarr.cs | 5 ++-- .../Notifications/Webhook/Webhook.cs | 5 ++-- .../Notifications/Webhook/WebhookBase.cs | 27 ++++++++++++------- .../Notifications/Webhook/WebhookMovie.cs | 8 ++++++ 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/Discord/Discord.cs b/src/NzbDrone.Core/Notifications/Discord/Discord.cs index 7c9166495..189064db6 100644 --- a/src/NzbDrone.Core/Notifications/Discord/Discord.cs +++ b/src/NzbDrone.Core/Notifications/Discord/Discord.cs @@ -625,7 +625,7 @@ private string GetTitle(Movie movie) private IEnumerable GetTagLabels(Movie movie) { - return movie.Tags?.Select(t => _tagRepository.Get(t)?.Label).Take(5).OrderBy(t => t); + return movie.Tags?.Select(t => _tagRepository.Get(t)?.Label).OrderBy(t => t).Take(5); } } } diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs index 8a7ee29b2..09f2df3cf 100644 --- a/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs +++ b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs @@ -6,6 +6,7 @@ using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Movies; using NzbDrone.Core.Notifications.Webhook; +using NzbDrone.Core.Tags; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Notifications.Notifiarr @@ -14,8 +15,8 @@ public class Notifiarr : WebhookBase { private readonly INotifiarrProxy _proxy; - public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService) - : base(configFileProvider, configService, localizationService) + public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService, ITagRepository tagRepository) + : base(configFileProvider, configService, localizationService, tagRepository) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs index 5115ef92f..915718116 100755 --- a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs @@ -5,6 +5,7 @@ using NzbDrone.Core.Localization; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Movies; +using NzbDrone.Core.Tags; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Notifications.Webhook @@ -13,8 +14,8 @@ public class Webhook : WebhookBase { private readonly IWebhookProxy _proxy; - public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService) - : base(configFileProvider, configService, localizationService) + public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService, ITagRepository tagRepository) + : base(configFileProvider, configService, localizationService, tagRepository) { _proxy = proxy; } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs index 322f3410c..51ddc42a4 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs @@ -5,6 +5,7 @@ using NzbDrone.Core.Localization; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Movies; +using NzbDrone.Core.Tags; using NzbDrone.Core.ThingiProvider; namespace NzbDrone.Core.Notifications.Webhook @@ -15,12 +16,14 @@ public abstract class WebhookBase : NotificationBase private readonly IConfigFileProvider _configFileProvider; private readonly IConfigService _configService; protected readonly ILocalizationService _localizationService; + private readonly ITagRepository _tagRepository; - protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService) + protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService, ITagRepository tagRepository) { _configFileProvider = configFileProvider; _configService = configService; _localizationService = localizationService; + _tagRepository = tagRepository; } protected WebhookGrabPayload BuildOnGrabPayload(GrabMessage message) @@ -33,7 +36,7 @@ protected WebhookGrabPayload BuildOnGrabPayload(GrabMessage message) EventType = WebhookEventType.Grab, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Movie = new WebhookMovie(message.Movie), + Movie = new WebhookMovie(message.Movie, tags: GetTagLabels(message.Movie)), RemoteMovie = new WebhookRemoteMovie(remoteMovie), Release = new WebhookRelease(quality, remoteMovie), DownloadClient = message.DownloadClientName, @@ -52,7 +55,7 @@ protected WebhookImportPayload BuildOnDownloadPayload(DownloadMessage message) EventType = WebhookEventType.Download, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Movie = new WebhookMovie(message.Movie), + Movie = new WebhookMovie(message.Movie, tags: GetTagLabels(message.Movie)), RemoteMovie = new WebhookRemoteMovie(message.Movie), MovieFile = new WebhookMovieFile(movieFile), Release = new WebhookGrabbedRelease(message.Release), @@ -83,7 +86,7 @@ protected WebhookAddedPayload BuildOnMovieAdded(Movie movie) EventType = WebhookEventType.MovieAdded, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Movie = new WebhookMovie(movie), + Movie = new WebhookMovie(movie, tags: GetTagLabels(movie)), AddMethod = movie.AddOptions.AddMethod }; } @@ -95,7 +98,7 @@ protected WebhookMovieFileDeletePayload BuildOnMovieFileDelete(MovieFileDeleteMe EventType = WebhookEventType.MovieFileDelete, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Movie = new WebhookMovie(deleteMessage.Movie), + Movie = new WebhookMovie(deleteMessage.Movie, tags: GetTagLabels(deleteMessage.Movie)), MovieFile = new WebhookMovieFile(deleteMessage.MovieFile), DeleteReason = deleteMessage.Reason }; @@ -108,7 +111,7 @@ protected WebhookMovieDeletePayload BuildOnMovieDelete(MovieDeleteMessage delete EventType = WebhookEventType.MovieDelete, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Movie = new WebhookMovie(deleteMessage.Movie), + Movie = new WebhookMovie(deleteMessage.Movie, tags: GetTagLabels(deleteMessage.Movie)), DeletedFiles = deleteMessage.DeletedFiles }; @@ -127,7 +130,7 @@ protected WebhookRenamePayload BuildOnRenamePayload(Movie movie, List new WebhookRenamedMovieFile(x)) }; } @@ -182,7 +185,7 @@ protected WebhookManualInteractionPayload BuildManualInteractionRequiredPayload( EventType = WebhookEventType.ManualInteractionRequired, InstanceName = _configFileProvider.InstanceName, ApplicationUrl = _configService.ApplicationUrl, - Movie = new WebhookMovie(message.Movie), + Movie = new WebhookMovie(message.Movie, tags: GetTagLabels(message.Movie)), DownloadInfo = new WebhookDownloadClientItem(quality, message.TrackedDownload.DownloadItem), DownloadClient = message.DownloadClientName, DownloadClientType = message.DownloadClientType, @@ -205,7 +208,8 @@ protected WebhookPayload BuildTestPayload() Title = "Test Title", Year = 1970, FolderPath = "C:\\testpath", - ReleaseDate = "1970-01-01" + ReleaseDate = "1970-01-01", + Tags = new[] { "test-tag" } }, RemoteMovie = new WebhookRemoteMovie { @@ -225,5 +229,10 @@ protected WebhookPayload BuildTestPayload() } }; } + + private IEnumerable GetTagLabels(Movie movie) + { + return movie.Tags?.Select(t => _tagRepository.Get(t)?.Label).OrderBy(t => t); + } } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookMovie.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookMovie.cs index f59d41ed6..c76928d83 100755 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookMovie.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookMovie.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.IO; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Movies; @@ -15,6 +16,7 @@ public class WebhookMovie public int TmdbId { get; set; } public string ImdbId { get; set; } public string Overview { get; set; } + public IEnumerable Tags { get; set; } public WebhookMovie() { @@ -32,6 +34,12 @@ public WebhookMovie(Movie movie) Overview = movie.MovieMetadata.Value.Overview; } + public WebhookMovie(Movie movie, IEnumerable tags) + : this(movie) + { + Tags = tags; + } + public WebhookMovie(Movie movie, MovieFile movieFile) : this(movie) {