From d999a4d582e62c7ca222d77794f1a7ebc246c0dc Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 15 Jan 2023 02:37:17 -0600 Subject: [PATCH] New: Notifiarr and Webhook Updates Closes #3062 --- .../NotificationBaseFixture.cs | 4 +- .../SynologyIndexerFixture.cs | 4 +- .../MediaFiles/Events/ArtistRenamedEvent.cs | 7 +- .../MediaFiles/RenameTrackFileService.cs | 17 +- .../MediaFiles/RenamedTrackFile.cs | 8 + .../Notifications/AlbumDownloadMessage.cs | 3 +- .../CustomScript/CustomScript.cs | 12 +- .../Notifications/Discord/Discord.cs | 3 +- .../Notifications/GrabMessage.cs | 3 +- .../Notifications/INotification.cs | 4 +- .../MediaBrowser/MediaBrowser.cs | 3 +- .../Notifications/Notifiarr/Notifiarr.cs | 128 +++++------- .../Notifications/Notifiarr/NotifiarrProxy.cs | 65 ++---- .../Notifications/NotificationBase.cs | 3 +- .../Notifications/NotificationService.cs | 7 +- .../Notifications/Plex/Server/PlexServer.cs | 3 +- .../Notifications/Slack/Slack.cs | 3 +- .../Notifications/Subsonic/Subsonic.cs | 3 +- .../Notifications/Synology/SynologyIndexer.cs | 3 +- .../Notifications/Webhook/Webhook.cs | 140 +++---------- .../WebhookApplicationUpdatePayload.cs | 2 - .../Notifications/Webhook/WebhookArtist.cs | 2 + .../Notifications/Webhook/WebhookBase.cs | 195 ++++++++++++++++++ .../Webhook/WebhookDownloadFailurePayload.cs | 13 ++ .../Notifications/Webhook/WebhookEventType.cs | 2 + .../Webhook/WebhookGrabPayload.cs | 1 + .../Webhook/WebhookImportPayload.cs | 1 + .../Notifications/Webhook/WebhookMethod.cs | 2 - .../Notifications/Webhook/WebhookPayload.cs | 1 + .../Webhook/WebhookRenamePayload.cs | 3 + .../Webhook/WebhookRenamedTrackFile.cs | 15 ++ src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs | 3 +- 32 files changed, 389 insertions(+), 274 deletions(-) create mode 100644 src/NzbDrone.Core/MediaFiles/RenamedTrackFile.cs create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookDownloadFailurePayload.cs create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookRenamedTrackFile.cs diff --git a/src/NzbDrone.Core.Test/NotificationTests/NotificationBaseFixture.cs b/src/NzbDrone.Core.Test/NotificationTests/NotificationBaseFixture.cs index c8b91dfe6..34ffc179f 100644 --- a/src/NzbDrone.Core.Test/NotificationTests/NotificationBaseFixture.cs +++ b/src/NzbDrone.Core.Test/NotificationTests/NotificationBaseFixture.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using FluentAssertions; using FluentValidation.Results; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; using NzbDrone.Core.Notifications; using NzbDrone.Core.ThingiProvider; @@ -57,7 +59,7 @@ namespace NzbDrone.Core.Test.NotificationTests TestLogger.Info("OnAlbumDownload was called"); } - public override void OnRename(Artist artist) + public override void OnRename(Artist artist, List renamedFiles) { TestLogger.Info("OnRename was called"); } diff --git a/src/NzbDrone.Core.Test/NotificationTests/SynologyIndexerFixture.cs b/src/NzbDrone.Core.Test/NotificationTests/SynologyIndexerFixture.cs index a241199e1..515d8bea2 100644 --- a/src/NzbDrone.Core.Test/NotificationTests/SynologyIndexerFixture.cs +++ b/src/NzbDrone.Core.Test/NotificationTests/SynologyIndexerFixture.cs @@ -65,7 +65,7 @@ namespace NzbDrone.Core.Test.NotificationTests { (Subject.Definition.Settings as SynologyIndexerSettings).UpdateLibrary = false; - Subject.OnRename(_artist); + Subject.OnRename(_artist, new List()); Mocker.GetMock() .Verify(v => v.UpdateFolder(_artist.Path), Times.Never()); @@ -95,7 +95,7 @@ namespace NzbDrone.Core.Test.NotificationTests [Test] public void should_update_entire_series_folder_on_rename() { - Subject.OnRename(_artist); + Subject.OnRename(_artist, new List()); Mocker.GetMock() .Verify(v => v.UpdateFolder(@"C:\Test\".AsOsAgnostic()), Times.Once()); diff --git a/src/NzbDrone.Core/MediaFiles/Events/ArtistRenamedEvent.cs b/src/NzbDrone.Core/MediaFiles/Events/ArtistRenamedEvent.cs index bea4ed219..b7631af18 100644 --- a/src/NzbDrone.Core/MediaFiles/Events/ArtistRenamedEvent.cs +++ b/src/NzbDrone.Core/MediaFiles/Events/ArtistRenamedEvent.cs @@ -1,4 +1,5 @@ -using NzbDrone.Common.Messaging; +using System.Collections.Generic; +using NzbDrone.Common.Messaging; using NzbDrone.Core.Music; namespace NzbDrone.Core.MediaFiles.Events @@ -6,10 +7,12 @@ namespace NzbDrone.Core.MediaFiles.Events public class ArtistRenamedEvent : IEvent { public Artist Artist { get; private set; } + public List RenamedFiles { get; private set; } - public ArtistRenamedEvent(Artist artist) + public ArtistRenamedEvent(Artist artist, List renamedFiles) { Artist = artist; + RenamedFiles = renamedFiles; } } } diff --git a/src/NzbDrone.Core/MediaFiles/RenameTrackFileService.cs b/src/NzbDrone.Core/MediaFiles/RenameTrackFileService.cs index 2e0d0d623..dde85f681 100644 --- a/src/NzbDrone.Core/MediaFiles/RenameTrackFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/RenameTrackFileService.cs @@ -112,11 +112,11 @@ namespace NzbDrone.Core.MediaFiles private void RenameFiles(List trackFiles, Artist artist) { - var renamed = new List(); + var renamed = new List(); foreach (var trackFile in trackFiles) { - var trackFilePath = trackFile.Path; + var previousPath = trackFile.Path; try { @@ -124,11 +124,16 @@ namespace NzbDrone.Core.MediaFiles _trackFileMover.MoveTrackFile(trackFile, artist); _mediaFileService.Update(trackFile); - renamed.Add(trackFile); + + renamed.Add(new RenamedTrackFile + { + TrackFile = trackFile, + PreviousPath = previousPath + }); _logger.Debug("Renamed track file: {0}", trackFile); - _eventAggregator.PublishEvent(new TrackFileRenamedEvent(artist, trackFile, trackFilePath)); + _eventAggregator.PublishEvent(new TrackFileRenamedEvent(artist, trackFile, previousPath)); } catch (SameFilenameException ex) { @@ -136,13 +141,13 @@ namespace NzbDrone.Core.MediaFiles } catch (Exception ex) { - _logger.Error(ex, "Failed to rename file {0}", trackFilePath); + _logger.Error(ex, "Failed to rename file {0}", previousPath); } } if (renamed.Any()) { - _eventAggregator.PublishEvent(new ArtistRenamedEvent(artist)); + _eventAggregator.PublishEvent(new ArtistRenamedEvent(artist, renamed)); _logger.Debug("Removing Empty Subfolders from: {0}", artist.Path); _diskProvider.RemoveEmptySubfolders(artist.Path); diff --git a/src/NzbDrone.Core/MediaFiles/RenamedTrackFile.cs b/src/NzbDrone.Core/MediaFiles/RenamedTrackFile.cs new file mode 100644 index 000000000..d5abcd852 --- /dev/null +++ b/src/NzbDrone.Core/MediaFiles/RenamedTrackFile.cs @@ -0,0 +1,8 @@ +namespace NzbDrone.Core.MediaFiles +{ + public class RenamedTrackFile + { + public TrackFile TrackFile { get; set; } + public string PreviousPath { get; set; } + } +} diff --git a/src/NzbDrone.Core/Notifications/AlbumDownloadMessage.cs b/src/NzbDrone.Core/Notifications/AlbumDownloadMessage.cs index f7781d98a..4cd26be55 100644 --- a/src/NzbDrone.Core/Notifications/AlbumDownloadMessage.cs +++ b/src/NzbDrone.Core/Notifications/AlbumDownloadMessage.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; @@ -12,7 +13,7 @@ namespace NzbDrone.Core.Notifications public AlbumRelease Release { get; set; } public List TrackFiles { get; set; } public List OldFiles { get; set; } - public string DownloadClient { get; set; } + public DownloadClientItemClientInfo DownloadClientInfo { get; set; } public string DownloadId { get; set; } public override string ToString() diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs index a252b3efe..d69d03b30 100644 --- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs +++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs @@ -9,6 +9,7 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Processes; using NzbDrone.Common.Serializer; using NzbDrone.Core.HealthCheck; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; @@ -56,7 +57,8 @@ namespace NzbDrone.Core.Notifications.CustomScript environmentVariables.Add("Lidarr_Release_Quality", remoteAlbum.ParsedAlbumInfo.Quality.Quality.Name); environmentVariables.Add("Lidarr_Release_QualityVersion", remoteAlbum.ParsedAlbumInfo.Quality.Revision.Version.ToString()); environmentVariables.Add("Lidarr_Release_ReleaseGroup", releaseGroup ?? string.Empty); - environmentVariables.Add("Lidarr_Download_Client", message.DownloadClient ?? string.Empty); + environmentVariables.Add("Lidarr_Download_Client", message.DownloadClientName ?? string.Empty); + environmentVariables.Add("Lidarr_Download_Client_Type", message.DownloadClientType ?? string.Empty); environmentVariables.Add("Lidarr_Download_Id", message.DownloadId ?? string.Empty); ExecuteScript(environmentVariables); @@ -80,7 +82,8 @@ namespace NzbDrone.Core.Notifications.CustomScript environmentVariables.Add("Lidarr_Album_MBId", album.ForeignAlbumId); environmentVariables.Add("Lidarr_AlbumRelease_MBId", release.ForeignReleaseId); environmentVariables.Add("Lidarr_Album_ReleaseDate", album.ReleaseDate.ToString()); - environmentVariables.Add("Lidarr_Download_Client", message.DownloadClient ?? string.Empty); + environmentVariables.Add("Lidarr_Download_Client", message.DownloadClientInfo?.Name ?? string.Empty); + environmentVariables.Add("Lidarr_Download_Client_Type", message.DownloadClientInfo?.Type ?? string.Empty); environmentVariables.Add("Lidarr_Download_Id", message.DownloadId ?? string.Empty); if (message.TrackFiles.Any()) @@ -96,7 +99,7 @@ namespace NzbDrone.Core.Notifications.CustomScript ExecuteScript(environmentVariables); } - public override void OnRename(Artist artist) + public override void OnRename(Artist artist, List renamedFiles) { var environmentVariables = new StringDictionary(); @@ -106,6 +109,9 @@ namespace NzbDrone.Core.Notifications.CustomScript environmentVariables.Add("Lidarr_Artist_Path", artist.Path); environmentVariables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId); environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type); + environmentVariables.Add("Lidarr_TrackFile_Ids", string.Join(",", renamedFiles.Select(e => e.TrackFile.Id))); + environmentVariables.Add("Lidarr_TrackFile_Paths", string.Join("|", renamedFiles.Select(e => e.TrackFile.Path))); + environmentVariables.Add("Lidarr_TrackFile_PreviousPaths", string.Join("|", renamedFiles.Select(e => e.PreviousPath))); ExecuteScript(environmentVariables); } diff --git a/src/NzbDrone.Core/Notifications/Discord/Discord.cs b/src/NzbDrone.Core/Notifications/Discord/Discord.cs index 0fb8d476b..8e170e4ab 100644 --- a/src/NzbDrone.Core/Notifications/Discord/Discord.cs +++ b/src/NzbDrone.Core/Notifications/Discord/Discord.cs @@ -4,6 +4,7 @@ using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; using NzbDrone.Core.MediaCover; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; using NzbDrone.Core.Notifications.Discord.Payloads; using NzbDrone.Core.Validation; @@ -206,7 +207,7 @@ namespace NzbDrone.Core.Notifications.Discord _proxy.SendPayload(payload, Settings); } - public override void OnRename(Artist artist) + public override void OnRename(Artist artist, List renamedFiles) { var attachments = new List { diff --git a/src/NzbDrone.Core/Notifications/GrabMessage.cs b/src/NzbDrone.Core/Notifications/GrabMessage.cs index 8b0974b9c..c2845f270 100644 --- a/src/NzbDrone.Core/Notifications/GrabMessage.cs +++ b/src/NzbDrone.Core/Notifications/GrabMessage.cs @@ -10,7 +10,8 @@ namespace NzbDrone.Core.Notifications public Artist Artist { get; set; } public RemoteAlbum Album { get; set; } public QualityModel Quality { get; set; } - public string DownloadClient { get; set; } + public string DownloadClientType { get; set; } + public string DownloadClientName { get; set; } public string DownloadId { get; set; } public override string ToString() diff --git a/src/NzbDrone.Core/Notifications/INotification.cs b/src/NzbDrone.Core/Notifications/INotification.cs index 9c368af21..fed97585c 100644 --- a/src/NzbDrone.Core/Notifications/INotification.cs +++ b/src/NzbDrone.Core/Notifications/INotification.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; using NzbDrone.Core.ThingiProvider; @@ -9,7 +11,7 @@ namespace NzbDrone.Core.Notifications void OnGrab(GrabMessage grabMessage); void OnReleaseImport(AlbumDownloadMessage message); - void OnRename(Artist artist); + void OnRename(Artist artist, List renamedFiles); void OnAlbumDelete(AlbumDeleteMessage deleteMessage); void OnArtistDelete(ArtistDeleteMessage deleteMessage); void OnHealthIssue(HealthCheck.HealthCheck healthCheck); diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs index 5222652dc..9285061c0 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using FluentValidation.Results; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; namespace NzbDrone.Core.Notifications.Emby @@ -38,7 +39,7 @@ namespace NzbDrone.Core.Notifications.Emby } } - public override void OnRename(Artist artist) + public override void OnRename(Artist artist, List renamedFiles) { if (Settings.UpdateLibrary) { diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs index 96f063558..9b7fa4dc8 100644 --- a/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs +++ b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs @@ -1,19 +1,20 @@ -using System; using System.Collections.Generic; -using System.Collections.Specialized; -using System.IO; -using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; -using NzbDrone.Core.HealthCheck; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Music; +using NzbDrone.Core.Notifications.Webhook; +using NzbDrone.Core.Validation; namespace NzbDrone.Core.Notifications.Notifiarr { - public class Notifiarr : NotificationBase + public class Notifiarr : WebhookBase { private readonly INotifiarrProxy _proxy; - public Notifiarr(INotifiarrProxy proxy) + public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider) + : base(configFileProvider) { _proxy = proxy; } @@ -23,98 +24,75 @@ namespace NzbDrone.Core.Notifications.Notifiarr public override void OnGrab(GrabMessage message) { - var artist = message.Artist; - var remoteAlbum = message.Album; - var releaseGroup = remoteAlbum.ParsedAlbumInfo.ReleaseGroup; - var variables = new StringDictionary(); - - variables.Add("Lidarr_EventType", "Grab"); - variables.Add("Lidarr_Artist_Id", artist.Id.ToString()); - variables.Add("Lidarr_Artist_Name", artist.Metadata.Value.Name); - variables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId); - variables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type); - variables.Add("Lidarr_Release_AlbumCount", remoteAlbum.Albums.Count.ToString()); - variables.Add("Lidarr_Release_AlbumReleaseDates", string.Join(",", remoteAlbum.Albums.Select(e => e.ReleaseDate))); - variables.Add("Lidarr_Release_AlbumTitles", string.Join("|", remoteAlbum.Albums.Select(e => e.Title))); - variables.Add("Lidarr_Release_AlbumMBIds", string.Join("|", remoteAlbum.Albums.Select(e => e.ForeignAlbumId))); - variables.Add("Lidarr_Release_Title", remoteAlbum.Release.Title); - variables.Add("Lidarr_Release_Indexer", remoteAlbum.Release.Indexer ?? string.Empty); - variables.Add("Lidarr_Release_Size", remoteAlbum.Release.Size.ToString()); - variables.Add("Lidarr_Release_Quality", remoteAlbum.ParsedAlbumInfo.Quality.Quality.Name); - variables.Add("Lidarr_Release_QualityVersion", remoteAlbum.ParsedAlbumInfo.Quality.Revision.Version.ToString()); - variables.Add("Lidarr_Release_ReleaseGroup", releaseGroup ?? string.Empty); - variables.Add("Lidarr_Download_Client", message.DownloadClient ?? string.Empty); - variables.Add("Lidarr_Download_Id", message.DownloadId ?? string.Empty); - - _proxy.SendNotification(variables, Settings); + _proxy.SendNotification(BuildOnGrabPayload(message), Settings); } public override void OnReleaseImport(AlbumDownloadMessage message) { - var artist = message.Artist; - var album = message.Album; - var release = message.Release; - var variables = new StringDictionary(); - - variables.Add("Lidarr_EventType", "Download"); - variables.Add("Lidarr_Artist_Id", artist.Id.ToString()); - variables.Add("Lidarr_Artist_Name", artist.Metadata.Value.Name); - variables.Add("Lidarr_Artist_Path", artist.Path); - variables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId); - variables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type); - variables.Add("Lidarr_Album_Id", album.Id.ToString()); - variables.Add("Lidarr_Album_Title", album.Title); - variables.Add("Lidarr_Album_MBId", album.ForeignAlbumId); - variables.Add("Lidarr_AlbumRelease_MBId", release.ForeignReleaseId); - variables.Add("Lidarr_Album_ReleaseDate", album.ReleaseDate.ToString()); - variables.Add("Lidarr_Download_Client", message.DownloadClient ?? string.Empty); - variables.Add("Lidarr_Download_Id", message.DownloadId ?? string.Empty); - - if (message.TrackFiles.Any()) - { - variables.Add("Lidarr_AddedTrackPaths", string.Join("|", message.TrackFiles.Select(e => e.Path))); - } + _proxy.SendNotification(BuildOnReleaseImportPayload(message), Settings); + } - if (message.OldFiles.Any()) - { - variables.Add("Lidarr_DeletedPaths", string.Join("|", message.OldFiles.Select(e => e.Path))); - } + public override void OnDownloadFailure(DownloadFailedMessage message) + { + _proxy.SendNotification(BuildOnDownloadFailurePayload(message), Settings); + } - _proxy.SendNotification(variables, Settings); + public override void OnImportFailure(AlbumDownloadMessage message) + { + _proxy.SendNotification(BuildOnImportFailurePayload(message), Settings); } - public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) + public override void OnRename(Artist artist, List renamedFiles) { - var variables = new StringDictionary(); + _proxy.SendNotification(BuildOnRenamePayload(artist, renamedFiles), Settings); + } - variables.Add("Lidarr_EventType", "HealthIssue"); - variables.Add("Lidarr_Health_Issue_Level", Enum.GetName(typeof(HealthCheckResult), healthCheck.Type)); - variables.Add("Lidarr_Health_Issue_Message", healthCheck.Message); - variables.Add("Lidarr_Health_Issue_Type", healthCheck.Source.Name); - variables.Add("Lidarr_Health_Issue_Wiki", healthCheck.WikiUrl.ToString() ?? string.Empty); + public override void OnTrackRetag(TrackRetagMessage message) + { + _proxy.SendNotification(BuildOnTrackRetagPayload(message), Settings); + } - _proxy.SendNotification(variables, Settings); + public override void OnAlbumDelete(AlbumDeleteMessage deleteMessage) + { + _proxy.SendNotification(BuildOnAlbumDelete(deleteMessage), Settings); } - public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage) + public override void OnArtistDelete(ArtistDeleteMessage deleteMessage) { - var variables = new StringDictionary(); + _proxy.SendNotification(BuildOnArtistDelete(deleteMessage), Settings); + } - variables.Add("Lidarr_EventType", "ApplicationUpdate"); - variables.Add("Lidarr_Update_Message", updateMessage.Message); - variables.Add("Lidarr_Update_NewVersion", updateMessage.NewVersion.ToString()); - variables.Add("Lidarr_Update_PreviousVersion", updateMessage.PreviousVersion.ToString()); + public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) + { + _proxy.SendNotification(BuildHealthPayload(healthCheck), Settings); + } - _proxy.SendNotification(variables, Settings); + public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage) + { + _proxy.SendNotification(BuildApplicationUpdatePayload(updateMessage), Settings); } public override ValidationResult Test() { var failures = new List(); - failures.AddIfNotNull(_proxy.Test(Settings)); + failures.AddIfNotNull(SendWebhookTest()); return new ValidationResult(failures); } + + private ValidationFailure SendWebhookTest() + { + try + { + _proxy.SendNotification(BuildTestPayload(), Settings); + } + catch (NotifiarrException ex) + { + return new NzbDroneValidationFailure("APIKey", ex.Message); + } + + return null; + } } } diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs index 41a1ed904..f2a246edd 100644 --- a/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs +++ b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs @@ -1,73 +1,43 @@ -using System; -using System.Collections.Specialized; -using FluentValidation.Results; -using NLog; -using NzbDrone.Common.Extensions; +using System.Net.Http; using NzbDrone.Common.Http; -using NzbDrone.Core.Configuration; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Notifications.Webhook; namespace NzbDrone.Core.Notifications.Notifiarr { public interface INotifiarrProxy { - void SendNotification(StringDictionary message, NotifiarrSettings settings); - ValidationFailure Test(NotifiarrSettings settings); + void SendNotification(WebhookPayload payload, NotifiarrSettings settings); } public class NotifiarrProxy : INotifiarrProxy { private const string URL = "https://notifiarr.com"; private readonly IHttpClient _httpClient; - private readonly IConfigFileProvider _configFileProvider; - private readonly Logger _logger; - public NotifiarrProxy(IHttpClient httpClient, IConfigFileProvider configFileProvider, Logger logger) + public NotifiarrProxy(IHttpClient httpClient) { _httpClient = httpClient; - _configFileProvider = configFileProvider; - _logger = logger; } - public void SendNotification(StringDictionary message, NotifiarrSettings settings) + public void SendNotification(WebhookPayload payload, NotifiarrSettings settings) { - ProcessNotification(message, settings); + ProcessNotification(payload, settings); } - public ValidationFailure Test(NotifiarrSettings settings) + private void ProcessNotification(WebhookPayload payload, NotifiarrSettings settings) { try { - var variables = new StringDictionary(); - variables.Add("Lidarr_EventType", "Test"); + var request = new HttpRequestBuilder(URL + "/api/v1/notification/lidarr") + .Accept(HttpAccept.Json) + .SetHeader("X-API-Key", settings.APIKey) + .Build(); - SendNotification(variables, settings); - return null; - } - catch (NotifiarrException ex) - { - return new ValidationFailure("APIKey", ex.Message); - } - catch (Exception ex) - { - _logger.Error(ex, ex.Message); - return new ValidationFailure("", "Unable to send test notification. Check the log for more details."); - } - } - - private void ProcessNotification(StringDictionary message, NotifiarrSettings settings) - { - try - { - var instanceName = _configFileProvider.InstanceName; - var requestBuilder = new HttpRequestBuilder(URL + "/api/v1/notification/lidarr/" + settings.APIKey).Post(); - requestBuilder.AddFormParameter("instanceName", instanceName).Build(); - - foreach (string key in message.Keys) - { - requestBuilder.AddFormParameter(key, message[key]); - } + request.Method = HttpMethod.Post; - var request = requestBuilder.Build(); + request.Headers.ContentType = "application/json"; + request.SetContent(payload.ToJson()); _httpClient.Post(request); } @@ -77,25 +47,20 @@ namespace NzbDrone.Core.Notifications.Notifiarr switch ((int)responseCode) { case 401: - _logger.Error("Unauthorized", "HTTP 401 - API key is invalid"); throw new NotifiarrException("API key is invalid"); case 400: - _logger.Error("Invalid Request", "HTTP 400 - Unable to send notification. Ensure Lidarr Integration is enabled & assigned a channel on Notifiarr"); throw new NotifiarrException("Unable to send notification. Ensure Lidarr Integration is enabled & assigned a channel on Notifiarr"); case 502: case 503: case 504: - _logger.Error("Service Unavailable", "Unable to send notification. Service Unavailable"); throw new NotifiarrException("Unable to send notification. Service Unavailable", ex); case 520: case 521: case 522: case 523: case 524: - _logger.Error(ex, "Cloudflare Related HTTP Error - Unable to send notification"); throw new NotifiarrException("Cloudflare Related HTTP Error - Unable to send notification", ex); default: - _logger.Error(ex, "Unknown HTTP Error - Unable to send notification"); throw new NotifiarrException("Unknown HTTP Error - Unable to send notification", ex); } } diff --git a/src/NzbDrone.Core/Notifications/NotificationBase.cs b/src/NzbDrone.Core/Notifications/NotificationBase.cs index 3a29ff9b4..2fd4bdd48 100644 --- a/src/NzbDrone.Core/Notifications/NotificationBase.cs +++ b/src/NzbDrone.Core/Notifications/NotificationBase.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using FluentValidation.Results; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; using NzbDrone.Core.ThingiProvider; @@ -50,7 +51,7 @@ namespace NzbDrone.Core.Notifications { } - public virtual void OnRename(Artist artist) + public virtual void OnRename(Artist artist, List renamedFiles) { } diff --git a/src/NzbDrone.Core/Notifications/NotificationService.cs b/src/NzbDrone.Core/Notifications/NotificationService.cs index 6ddaa7a71..f440c227a 100644 --- a/src/NzbDrone.Core/Notifications/NotificationService.cs +++ b/src/NzbDrone.Core/Notifications/NotificationService.cs @@ -126,7 +126,8 @@ namespace NzbDrone.Core.Notifications Artist = message.Album.Artist, Quality = message.Album.ParsedAlbumInfo.Quality, Album = message.Album, - DownloadClient = message.DownloadClient, + DownloadClientName = message.DownloadClientName, + DownloadClientType = message.DownloadClient, DownloadId = message.DownloadId }; @@ -161,7 +162,7 @@ namespace NzbDrone.Core.Notifications Artist = message.Artist, Album = message.Album, Release = message.AlbumRelease, - DownloadClient = message.DownloadClientInfo?.Name, + DownloadClientInfo = message.DownloadClientInfo, DownloadId = message.DownloadId, TrackFiles = message.ImportedTracks, OldFiles = message.OldFiles, @@ -194,7 +195,7 @@ namespace NzbDrone.Core.Notifications { if (ShouldHandleArtist(notification.Definition, message.Artist)) { - notification.OnRename(message.Artist); + notification.OnRename(message.Artist, message.RenamedFiles); } } catch (Exception ex) diff --git a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServer.cs b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServer.cs index 97a980c08..a2cc153de 100644 --- a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServer.cs +++ b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServer.cs @@ -6,6 +6,7 @@ using NLog; using NzbDrone.Common.Cache; using NzbDrone.Common.Extensions; using NzbDrone.Core.Exceptions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; using NzbDrone.Core.Notifications.Plex.PlexTv; using NzbDrone.Core.Validation; @@ -43,7 +44,7 @@ namespace NzbDrone.Core.Notifications.Plex.Server UpdateIfEnabled(message.Artist); } - public override void OnRename(Artist artist) + public override void OnRename(Artist artist, List renamedFiles) { UpdateIfEnabled(artist); } diff --git a/src/NzbDrone.Core/Notifications/Slack/Slack.cs b/src/NzbDrone.Core/Notifications/Slack/Slack.cs index e5ebb4a93..286d853f7 100644 --- a/src/NzbDrone.Core/Notifications/Slack/Slack.cs +++ b/src/NzbDrone.Core/Notifications/Slack/Slack.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using FluentValidation.Results; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; using NzbDrone.Core.Notifications.Slack.Payloads; using NzbDrone.Core.Validation; @@ -54,7 +55,7 @@ namespace NzbDrone.Core.Notifications.Slack _proxy.SendPayload(payload, Settings); } - public override void OnRename(Artist artist) + public override void OnRename(Artist artist, List renamedFiles) { var attachments = new List { diff --git a/src/NzbDrone.Core/Notifications/Subsonic/Subsonic.cs b/src/NzbDrone.Core/Notifications/Subsonic/Subsonic.cs index 371152baa..c8c97a260 100644 --- a/src/NzbDrone.Core/Notifications/Subsonic/Subsonic.cs +++ b/src/NzbDrone.Core/Notifications/Subsonic/Subsonic.cs @@ -3,6 +3,7 @@ using System.Net.Sockets; using FluentValidation.Results; using NLog; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; namespace NzbDrone.Core.Notifications.Subsonic @@ -35,7 +36,7 @@ namespace NzbDrone.Core.Notifications.Subsonic Update(); } - public override void OnRename(Artist artist) + public override void OnRename(Artist artist, List renamedFiles) { Update(); } diff --git a/src/NzbDrone.Core/Notifications/Synology/SynologyIndexer.cs b/src/NzbDrone.Core/Notifications/Synology/SynologyIndexer.cs index ab20bbefd..b1e5f0333 100644 --- a/src/NzbDrone.Core/Notifications/Synology/SynologyIndexer.cs +++ b/src/NzbDrone.Core/Notifications/Synology/SynologyIndexer.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using FluentValidation.Results; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; namespace NzbDrone.Core.Notifications.Synology @@ -38,7 +39,7 @@ namespace NzbDrone.Core.Notifications.Synology } } - public override void OnRename(Artist artist) + public override void OnRename(Artist artist, List renamedFiles) { if (Settings.UpdateLibrary) { diff --git a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs index 4e890fec9..0036ddcea 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs @@ -2,16 +2,19 @@ using System.Collections.Generic; using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Notifications.Webhook { - public class Webhook : NotificationBase + public class Webhook : WebhookBase { private readonly IWebhookProxy _proxy; - public Webhook(IWebhookProxy proxy) + public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider) + : base(configFileProvider) { _proxy = proxy; } @@ -20,129 +23,52 @@ namespace NzbDrone.Core.Notifications.Webhook public override void OnGrab(GrabMessage message) { - var remoteAlbum = message.Album; - var quality = message.Quality; - - var payload = new WebhookGrabPayload - { - EventType = WebhookEventType.Grab, - Artist = new WebhookArtist(message.Artist), - Albums = remoteAlbum.Albums.ConvertAll(x => new WebhookAlbum(x) - { - // TODO: Stop passing these parameters inside an album v3 - Quality = quality.Quality.Name, - QualityVersion = quality.Revision.Version, - ReleaseGroup = remoteAlbum.ParsedAlbumInfo.ReleaseGroup - }), - Release = new WebhookRelease(quality, remoteAlbum), - DownloadClient = message.DownloadClient, - DownloadId = message.DownloadId - }; - - _proxy.SendWebhook(payload, Settings); + _proxy.SendWebhook(BuildOnGrabPayload(message), Settings); } public override void OnReleaseImport(AlbumDownloadMessage message) { - var trackFiles = message.TrackFiles; - - var payload = new WebhookImportPayload - { - EventType = WebhookEventType.Download, - Artist = new WebhookArtist(message.Artist), - Tracks = trackFiles.SelectMany(x => x.Tracks.Value.Select(y => new WebhookTrack(y) - { - // TODO: Stop passing these parameters inside an episode v3 - Quality = x.Quality.Quality.Name, - QualityVersion = x.Quality.Revision.Version, - ReleaseGroup = x.ReleaseGroup - })).ToList(), - TrackFiles = trackFiles.ConvertAll(x => new WebhookTrackFile(x)), - IsUpgrade = message.OldFiles.Any(), - DownloadClient = message.DownloadClient, - DownloadId = message.DownloadId - }; - - if (message.OldFiles.Any()) - { - payload.DeletedFiles = message.OldFiles.ConvertAll(x => new WebhookTrackFile(x)); - } + _proxy.SendWebhook(BuildOnReleaseImportPayload(message), Settings); + } - _proxy.SendWebhook(payload, Settings); + public override void OnDownloadFailure(DownloadFailedMessage message) + { + _proxy.SendWebhook(BuildOnDownloadFailurePayload(message), Settings); } - public override void OnRename(Artist artist) + public override void OnImportFailure(AlbumDownloadMessage message) { - var payload = new WebhookRenamePayload - { - EventType = WebhookEventType.Rename, - Artist = new WebhookArtist(artist) - }; + _proxy.SendWebhook(BuildOnImportFailurePayload(message), Settings); + } - _proxy.SendWebhook(payload, Settings); + public override void OnRename(Artist artist, List renamedFiles) + { + _proxy.SendWebhook(BuildOnRenamePayload(artist, renamedFiles), Settings); } public override void OnTrackRetag(TrackRetagMessage message) { - var payload = new WebhookRetagPayload - { - EventType = WebhookEventType.Retag, - Artist = new WebhookArtist(message.Artist), - TrackFile = new WebhookTrackFile(message.TrackFile) - }; - - _proxy.SendWebhook(payload, Settings); + _proxy.SendWebhook(BuildOnTrackRetagPayload(message), Settings); } public override void OnAlbumDelete(AlbumDeleteMessage deleteMessage) { - var payload = new WebhookAlbumDeletePayload - { - EventType = WebhookEventType.AlbumDelete, - Album = new WebhookAlbum(deleteMessage.Album), - DeletedFiles = deleteMessage.DeletedFiles - }; - - _proxy.SendWebhook(payload, Settings); + _proxy.SendWebhook(BuildOnAlbumDelete(deleteMessage), Settings); } public override void OnArtistDelete(ArtistDeleteMessage deleteMessage) { - var payload = new WebhookArtistDeletePayload - { - EventType = WebhookEventType.ArtistDelete, - Artist = new WebhookArtist(deleteMessage.Artist), - DeletedFiles = deleteMessage.DeletedFiles - }; - - _proxy.SendWebhook(payload, Settings); + _proxy.SendWebhook(BuildOnArtistDelete(deleteMessage), Settings); } public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) { - var payload = new WebhookHealthPayload - { - EventType = WebhookEventType.Health, - Level = healthCheck.Type, - Message = healthCheck.Message, - Type = healthCheck.Source.Name, - WikiUrl = healthCheck.WikiUrl?.ToString() - }; - - _proxy.SendWebhook(payload, Settings); + _proxy.SendWebhook(BuildHealthPayload(healthCheck), Settings); } public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage) { - var payload = new WebhookApplicationUpdatePayload - { - EventType = WebhookEventType.ApplicationUpdate, - Message = updateMessage.Message, - PreviousVersion = updateMessage.PreviousVersion.ToString(), - NewVersion = updateMessage.NewVersion.ToString() - }; - - _proxy.SendWebhook(payload, Settings); + _proxy.SendWebhook(BuildApplicationUpdatePayload(updateMessage), Settings); } public override string Name => "Webhook"; @@ -160,27 +86,7 @@ namespace NzbDrone.Core.Notifications.Webhook { try { - var payload = new WebhookGrabPayload - { - EventType = WebhookEventType.Test, - Artist = new WebhookArtist() - { - Id = 1, - Name = "Test Name", - Path = "C:\\testpath", - MBId = "aaaaa-aaa-aaaa-aaaaaa" - }, - Albums = new List() - { - new WebhookAlbum() - { - Id = 123, - Title = "Test title" - } - } - }; - - _proxy.SendWebhook(payload, Settings); + _proxy.SendWebhook(BuildTestPayload(), Settings); } catch (WebhookException ex) { diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookApplicationUpdatePayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookApplicationUpdatePayload.cs index e05be69bc..66a6ff382 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookApplicationUpdatePayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookApplicationUpdatePayload.cs @@ -1,5 +1,3 @@ -using NzbDrone.Core.HealthCheck; - namespace NzbDrone.Core.Notifications.Webhook { public class WebhookApplicationUpdatePayload : WebhookPayload diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookArtist.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookArtist.cs index 11e9199bd..3a0f5f62e 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookArtist.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookArtist.cs @@ -8,6 +8,7 @@ namespace NzbDrone.Core.Notifications.Webhook public string Name { get; set; } public string Path { get; set; } public string MBId { get; set; } + public string Type { get; set; } public WebhookArtist() { @@ -18,6 +19,7 @@ namespace NzbDrone.Core.Notifications.Webhook Id = artist.Id; Name = artist.Name; Path = artist.Path; + Type = artist.Metadata.Value.Type; MBId = artist.Metadata.Value.ForeignArtistId; } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs new file mode 100644 index 000000000..3fd3756d1 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs @@ -0,0 +1,195 @@ +using System.Collections.Generic; +using System.Linq; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Music; +using NzbDrone.Core.ThingiProvider; + +namespace NzbDrone.Core.Notifications.Webhook +{ + public abstract class WebhookBase : NotificationBase + where TSettings : IProviderConfig, new() + { + private readonly IConfigFileProvider _configFileProvider; + + protected WebhookBase(IConfigFileProvider configFileProvider) + : base() + { + _configFileProvider = configFileProvider; + } + + public WebhookGrabPayload BuildOnGrabPayload(GrabMessage message) + { + var remoteAlbum = message.Album; + var quality = message.Quality; + + return new WebhookGrabPayload + { + EventType = WebhookEventType.Grab, + InstanceName = _configFileProvider.InstanceName, + Artist = new WebhookArtist(message.Artist), + Release = new WebhookRelease(quality, remoteAlbum), + DownloadClient = message.DownloadClientName, + DownloadClientType = message.DownloadClientType, + DownloadId = message.DownloadId + }; + } + + public WebhookImportPayload BuildOnReleaseImportPayload(AlbumDownloadMessage message) + { + var trackFiles = message.TrackFiles; + + var payload = new WebhookImportPayload + { + EventType = WebhookEventType.Download, + InstanceName = _configFileProvider.InstanceName, + Artist = new WebhookArtist(message.Artist), + Tracks = trackFiles.SelectMany(x => x.Tracks.Value.Select(y => new WebhookTrack(y))).ToList(), + TrackFiles = trackFiles.ConvertAll(x => new WebhookTrackFile(x)), + IsUpgrade = message.OldFiles.Any(), + DownloadClient = message.DownloadClientInfo?.Name, + DownloadClientType = message.DownloadClientInfo?.Type, + DownloadId = message.DownloadId + }; + + if (message.OldFiles.Any()) + { + payload.DeletedFiles = message.OldFiles.ConvertAll(x => new WebhookTrackFile(x)); + } + + return payload; + } + + public WebhookDownloadFailurePayload BuildOnDownloadFailurePayload(DownloadFailedMessage message) + { + return new WebhookDownloadFailurePayload + { + EventType = WebhookEventType.DownloadFailure, + InstanceName = _configFileProvider.InstanceName, + DownloadClient = message.DownloadClient, + DownloadId = message.DownloadId, + Quality = message.Quality.Quality.Name, + QualityVersion = message.Quality.Revision.Version, + ReleaseTitle = message.SourceTitle + }; + } + + public WebhookImportPayload BuildOnImportFailurePayload(AlbumDownloadMessage message) + { + var trackFiles = message.TrackFiles; + + var payload = new WebhookImportPayload + { + EventType = WebhookEventType.ImportFailure, + InstanceName = _configFileProvider.InstanceName, + Artist = new WebhookArtist(message.Artist), + Tracks = trackFiles.SelectMany(x => x.Tracks.Value.Select(y => new WebhookTrack(y))).ToList(), + TrackFiles = trackFiles.ConvertAll(x => new WebhookTrackFile(x)), + IsUpgrade = message.OldFiles.Any(), + DownloadClient = message.DownloadClientInfo?.Name, + DownloadClientType = message.DownloadClientInfo?.Type, + DownloadId = message.DownloadId + }; + + if (message.OldFiles.Any()) + { + payload.DeletedFiles = message.OldFiles.ConvertAll(x => new WebhookTrackFile(x)); + } + + return payload; + } + + public WebhookRenamePayload BuildOnRenamePayload(Artist artist, List renamedFiles) + { + return new WebhookRenamePayload + { + EventType = WebhookEventType.Rename, + InstanceName = _configFileProvider.InstanceName, + Artist = new WebhookArtist(artist), + RenamedTrackFiles = renamedFiles.ConvertAll(x => new WebhookRenamedTrackFile(x)) + }; + } + + public WebhookRetagPayload BuildOnTrackRetagPayload(TrackRetagMessage message) + { + return new WebhookRetagPayload + { + EventType = WebhookEventType.Retag, + InstanceName = _configFileProvider.InstanceName, + Artist = new WebhookArtist(message.Artist), + TrackFile = new WebhookTrackFile(message.TrackFile) + }; + } + + public WebhookAlbumDeletePayload BuildOnAlbumDelete(AlbumDeleteMessage deleteMessage) + { + return new WebhookAlbumDeletePayload + { + EventType = WebhookEventType.AlbumDelete, + InstanceName = _configFileProvider.InstanceName, + Album = new WebhookAlbum(deleteMessage.Album), + DeletedFiles = deleteMessage.DeletedFiles + }; + } + + public WebhookArtistDeletePayload BuildOnArtistDelete(ArtistDeleteMessage deleteMessage) + { + return new WebhookArtistDeletePayload + { + EventType = WebhookEventType.ArtistDelete, + InstanceName = _configFileProvider.InstanceName, + Artist = new WebhookArtist(deleteMessage.Artist), + DeletedFiles = deleteMessage.DeletedFiles + }; + } + + protected WebhookHealthPayload BuildHealthPayload(HealthCheck.HealthCheck healthCheck) + { + return new WebhookHealthPayload + { + EventType = WebhookEventType.Health, + InstanceName = _configFileProvider.InstanceName, + Level = healthCheck.Type, + Message = healthCheck.Message, + Type = healthCheck.Source.Name, + WikiUrl = healthCheck.WikiUrl?.ToString() + }; + } + + protected WebhookApplicationUpdatePayload BuildApplicationUpdatePayload(ApplicationUpdateMessage updateMessage) + { + return new WebhookApplicationUpdatePayload + { + EventType = WebhookEventType.ApplicationUpdate, + InstanceName = _configFileProvider.InstanceName, + Message = updateMessage.Message, + PreviousVersion = updateMessage.PreviousVersion.ToString(), + NewVersion = updateMessage.NewVersion.ToString() + }; + } + + protected WebhookPayload BuildTestPayload() + { + return new WebhookGrabPayload + { + EventType = WebhookEventType.Test, + InstanceName = _configFileProvider.InstanceName, + Artist = new WebhookArtist() + { + Id = 1, + Name = "Test Name", + Path = "C:\\testpath", + MBId = "aaaaa-aaa-aaaa-aaaaaa" + }, + Albums = new List() + { + new WebhookAlbum() + { + Id = 123, + Title = "Test title" + } + } + }; + } + } +} diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookDownloadFailurePayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookDownloadFailurePayload.cs new file mode 100644 index 000000000..fe12b5781 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookDownloadFailurePayload.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace NzbDrone.Core.Notifications.Webhook +{ + public class WebhookDownloadFailurePayload : WebhookPayload + { + public string Quality { get; set; } + public int QualityVersion { get; set; } + public string ReleaseTitle { get; set; } + public string DownloadClient { get; set; } + public string DownloadId { get; set; } + } +} diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs index d9481ce53..e862f7000 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs @@ -11,6 +11,8 @@ namespace NzbDrone.Core.Notifications.Webhook Test, Grab, Download, + DownloadFailure, + ImportFailure, Rename, AlbumDelete, ArtistDelete, diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs index 27a5ca4a7..3bef045fc 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs @@ -8,6 +8,7 @@ namespace NzbDrone.Core.Notifications.Webhook public List Albums { get; set; } public WebhookRelease Release { get; set; } public string DownloadClient { get; set; } + public string DownloadClientType { get; set; } public string DownloadId { get; set; } } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookImportPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookImportPayload.cs index bc98d0bc9..e85c8306a 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookImportPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookImportPayload.cs @@ -10,6 +10,7 @@ namespace NzbDrone.Core.Notifications.Webhook public List DeletedFiles { get; set; } public bool IsUpgrade { get; set; } public string DownloadClient { get; set; } + public string DownloadClientType { get; set; } public string DownloadId { get; set; } } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookMethod.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookMethod.cs index e3705d69b..a1d7b5137 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookMethod.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookMethod.cs @@ -1,5 +1,3 @@ -using NzbDrone.Common.Http; - namespace NzbDrone.Core.Notifications.Webhook { public enum WebhookMethod diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs index 4b63a748e..05d51c7c1 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs @@ -3,5 +3,6 @@ namespace NzbDrone.Core.Notifications.Webhook public class WebhookPayload { public WebhookEventType EventType { get; set; } + public string InstanceName { get; set; } } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs index 94e4e5cc3..c42a05a53 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs @@ -1,7 +1,10 @@ +using System.Collections.Generic; + namespace NzbDrone.Core.Notifications.Webhook { public class WebhookRenamePayload : WebhookPayload { public WebhookArtist Artist { get; set; } + public List RenamedTrackFiles { get; set; } } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamedTrackFile.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamedTrackFile.cs new file mode 100644 index 000000000..9c1cec794 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamedTrackFile.cs @@ -0,0 +1,15 @@ +using NzbDrone.Core.MediaFiles; + +namespace NzbDrone.Core.Notifications.Webhook +{ + public class WebhookRenamedTrackFile : WebhookTrackFile + { + public WebhookRenamedTrackFile(RenamedTrackFile renamedMovie) + : base(renamedMovie.TrackFile) + { + PreviousPath = renamedMovie.PreviousPath; + } + + public string PreviousPath { get; set; } + } +} diff --git a/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs b/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs index c0cbe0cfa..ee8c549fa 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs @@ -4,6 +4,7 @@ using System.Net.Sockets; using FluentValidation.Results; using NLog; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Music; namespace NzbDrone.Core.Notifications.Xbmc @@ -36,7 +37,7 @@ namespace NzbDrone.Core.Notifications.Xbmc UpdateAndClean(message.Artist, message.OldFiles.Any()); } - public override void OnRename(Artist artist) + public override void OnRename(Artist artist, List renamedFiles) { UpdateAndClean(artist); }