diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 37fb5a74b..d856a395c 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -653,7 +653,6 @@ "EpisodeHistoryLoadError": "Unable to load episode history", "EpisodeImported": "Episode Imported", "EpisodeImportedTooltip": "Episode downloaded successfully and picked up from download client", - "EpisodesInSeason": "{episodeCount} episodes in season", "EpisodeInfo": "Episode Info", "EpisodeIsDownloading": "Episode is downloading", "EpisodeIsNotMonitored": "Episode is not monitored", @@ -669,6 +668,7 @@ "EpisodeTitleRequired": "Episode Title Required", "EpisodeTitleRequiredHelpText": "Prevent importing for up to 48 hours if the episode title is in the naming format and the episode title is TBA", "Episodes": "Episodes", + "EpisodesInSeason": "{episodeCount} episodes in season", "EpisodesLoadError": "Unable to load episodes", "Error": "Error", "ErrorLoadingContent": "There was an error loading this content", @@ -1329,6 +1329,8 @@ "NotificationTriggersHelpText": "Select which events should trigger this notification", "NotificationsAppriseSettingsConfigurationKey": "Apprise Configuration Key", "NotificationsAppriseSettingsConfigurationKeyHelpText": "Configuration Key for the Persistent Storage Solution. Leave empty if Stateless URLs is used.", + "NotificationsAppriseSettingsIncludePoster": "Include Poster", + "NotificationsAppriseSettingsIncludePosterHelpText": "Include poster in message", "NotificationsAppriseSettingsNotificationType": "Apprise Notification Type", "NotificationsAppriseSettingsPasswordHelpText": "HTTP Basic Auth Password", "NotificationsAppriseSettingsServerUrl": "Apprise Server URL", diff --git a/src/NzbDrone.Core/Notifications/Apprise/Apprise.cs b/src/NzbDrone.Core/Notifications/Apprise/Apprise.cs index 04d08901f..325186777 100644 --- a/src/NzbDrone.Core/Notifications/Apprise/Apprise.cs +++ b/src/NzbDrone.Core/Notifications/Apprise/Apprise.cs @@ -1,6 +1,9 @@ using System.Collections.Generic; +using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaCover; +using NzbDrone.Core.Tv; namespace NzbDrone.Core.Notifications.Apprise { @@ -19,52 +22,52 @@ namespace NzbDrone.Core.Notifications.Apprise public override void OnGrab(GrabMessage grabMessage) { - _proxy.SendNotification(EPISODE_GRABBED_TITLE, grabMessage.Message, Settings); + _proxy.SendNotification(EPISODE_GRABBED_TITLE, grabMessage.Message, GetPosterUrl(grabMessage.Series), Settings); } public override void OnDownload(DownloadMessage message) { - _proxy.SendNotification(EPISODE_DOWNLOADED_TITLE, message.Message, Settings); + _proxy.SendNotification(EPISODE_DOWNLOADED_TITLE, message.Message, GetPosterUrl(message.Series), Settings); } public override void OnImportComplete(ImportCompleteMessage message) { - _proxy.SendNotification(IMPORT_COMPLETE_TITLE, message.Message, Settings); + _proxy.SendNotification(IMPORT_COMPLETE_TITLE, message.Message, GetPosterUrl(message.Series), Settings); } public override void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage) { - _proxy.SendNotification(EPISODE_DELETED_TITLE, deleteMessage.Message, Settings); + _proxy.SendNotification(EPISODE_DELETED_TITLE, deleteMessage.Message, GetPosterUrl(deleteMessage.Series), Settings); } public override void OnSeriesAdd(SeriesAddMessage message) { - _proxy.SendNotification(SERIES_ADDED_TITLE, message.Message, Settings); + _proxy.SendNotification(SERIES_ADDED_TITLE, message.Message, GetPosterUrl(message.Series), Settings); } public override void OnSeriesDelete(SeriesDeleteMessage deleteMessage) { - _proxy.SendNotification(SERIES_DELETED_TITLE, deleteMessage.Message, Settings); + _proxy.SendNotification(SERIES_DELETED_TITLE, deleteMessage.Message, GetPosterUrl(deleteMessage.Series), Settings); } public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) { - _proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheck.Message, Settings); + _proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheck.Message, null, Settings); } public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck) { - _proxy.SendNotification(HEALTH_RESTORED_TITLE, $"The following issue is now resolved: {previousCheck.Message}", Settings); + _proxy.SendNotification(HEALTH_RESTORED_TITLE, $"The following issue is now resolved: {previousCheck.Message}", null, Settings); } public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage) { - _proxy.SendNotification(APPLICATION_UPDATE_TITLE, updateMessage.Message, Settings); + _proxy.SendNotification(APPLICATION_UPDATE_TITLE, updateMessage.Message, null, Settings); } public override void OnManualInteractionRequired(ManualInteractionRequiredMessage message) { - _proxy.SendNotification(MANUAL_INTERACTION_REQUIRED_TITLE, message.Message, Settings); + _proxy.SendNotification(MANUAL_INTERACTION_REQUIRED_TITLE, message.Message, GetPosterUrl(message.Series), Settings); } public override ValidationResult Test() @@ -75,5 +78,10 @@ namespace NzbDrone.Core.Notifications.Apprise return new ValidationResult(failures); } + + private static string GetPosterUrl(Series series) + { + return series?.Images?.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.RemoteUrl; + } } } diff --git a/src/NzbDrone.Core/Notifications/Apprise/ApprisePayload.cs b/src/NzbDrone.Core/Notifications/Apprise/ApprisePayload.cs index 71ab0ea61..4d044a53a 100644 --- a/src/NzbDrone.Core/Notifications/Apprise/ApprisePayload.cs +++ b/src/NzbDrone.Core/Notifications/Apprise/ApprisePayload.cs @@ -8,6 +8,8 @@ namespace NzbDrone.Core.Notifications.Apprise public string Body { get; set; } + public string Attachment { get; set; } + public AppriseNotificationType Type { get; set; } public string Tag { get; set; } diff --git a/src/NzbDrone.Core/Notifications/Apprise/AppriseProxy.cs b/src/NzbDrone.Core/Notifications/Apprise/AppriseProxy.cs index 1c4d9b199..6405b75b0 100644 --- a/src/NzbDrone.Core/Notifications/Apprise/AppriseProxy.cs +++ b/src/NzbDrone.Core/Notifications/Apprise/AppriseProxy.cs @@ -13,7 +13,7 @@ namespace NzbDrone.Core.Notifications.Apprise { public interface IAppriseProxy { - void SendNotification(string title, string message, AppriseSettings settings); + void SendNotification(string title, string message, string posterUrl, AppriseSettings settings); ValidationFailure Test(AppriseSettings settings); } @@ -30,7 +30,7 @@ namespace NzbDrone.Core.Notifications.Apprise _logger = logger; } - public void SendNotification(string title, string message, AppriseSettings settings) + public void SendNotification(string title, string message, string posterUrl, AppriseSettings settings) { var payload = new ApprisePayload { @@ -61,6 +61,11 @@ namespace NzbDrone.Core.Notifications.Apprise payload.Tag = settings.Tags.Join(","); } + if (settings.IncludePoster && posterUrl.IsNotNullOrWhiteSpace()) + { + payload.Attachment = posterUrl; + } + if (settings.AuthUsername.IsNotNullOrWhiteSpace() || settings.AuthPassword.IsNotNullOrWhiteSpace()) { requestBuilder.NetworkCredential = new BasicNetworkCredential(settings.AuthUsername, settings.AuthPassword); @@ -86,10 +91,11 @@ namespace NzbDrone.Core.Notifications.Apprise { const string title = "Sonarr - Test Notification"; const string body = "Success! You have properly configured your apprise notification settings."; + const string posterUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/128.png"; try { - SendNotification(title, body, settings); + SendNotification(title, body, posterUrl, settings); } catch (AppriseException ex) when (ex.InnerException is HttpException httpException) { diff --git a/src/NzbDrone.Core/Notifications/Apprise/AppriseSettings.cs b/src/NzbDrone.Core/Notifications/Apprise/AppriseSettings.cs index 50d76a581..44cd503ad 100644 --- a/src/NzbDrone.Core/Notifications/Apprise/AppriseSettings.cs +++ b/src/NzbDrone.Core/Notifications/Apprise/AppriseSettings.cs @@ -59,10 +59,13 @@ namespace NzbDrone.Core.Notifications.Apprise [FieldDefinition(5, Label = "NotificationsAppriseSettingsTags", Type = FieldType.Tag, HelpText = "NotificationsAppriseSettingsTagsHelpText")] public IEnumerable Tags { get; set; } - [FieldDefinition(6, Label = "Username", Type = FieldType.Textbox, HelpText = "NotificationsAppriseSettingsUsernameHelpText", Privacy = PrivacyLevel.UserName)] + [FieldDefinition(6, Label = "NotificationsAppriseSettingsIncludePoster", Type = FieldType.Checkbox, HelpText = "NotificationsAppriseSettingsIncludePosterHelpText")] + public bool IncludePoster { get; set; } + + [FieldDefinition(7, Label = "Username", Type = FieldType.Textbox, HelpText = "NotificationsAppriseSettingsUsernameHelpText", Privacy = PrivacyLevel.UserName)] public string AuthUsername { get; set; } - [FieldDefinition(7, Label = "Password", Type = FieldType.Password, HelpText = "NotificationsAppriseSettingsPasswordHelpText", Privacy = PrivacyLevel.Password)] + [FieldDefinition(8, Label = "Password", Type = FieldType.Password, HelpText = "NotificationsAppriseSettingsPasswordHelpText", Privacy = PrivacyLevel.Password)] public string AuthPassword { get; set; } public override NzbDroneValidationResult Validate()