New: Options to send Image and Metadata links for Pushcut Notifications

Co-authored-by: Mark McDowall <mark@mcdowall.ca>
This commit is contained in:
Denis Gheorghescu 2025-03-16 01:37:40 +02:00 committed by GitHub
parent 3cb6f866cc
commit 6f451b2206
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 123 additions and 59 deletions

View file

@ -1423,6 +1423,10 @@
"NotificationsPushBulletSettingsDeviceIds": "Device IDs",
"NotificationsPushBulletSettingsDeviceIdsHelpText": "List of device IDs (leave blank to send to all devices)",
"NotificationsPushcutSettingsApiKeyHelpText": "API Keys can be managed in the Account view of the Pushcut app",
"NotificationsPushcutSettingsIncludePoster": "Include Poster",
"NotificationsPushcutSettingsIncludePosterHelpText": "Include poster with notification",
"NotificationsPushcutSettingsMetadataLinks": "Metadata Links",
"NotificationsPushcutSettingsMetadataLinksHelpText": "Add a links to series metadata when sending notifications",
"NotificationsPushcutSettingsNotificationName": "Notification Name",
"NotificationsPushcutSettingsNotificationNameHelpText": "Notification name from Notifications tab of the Pushcut app",
"NotificationsPushcutSettingsTimeSensitive": "Time Sensitive",

View file

@ -1,12 +1,12 @@
namespace NzbDrone.Core.Notifications.Telegram
namespace NzbDrone.Core.Notifications
{
public class TelegramLink
public class NotificationMetadataLink
{
public MetadataLinkType? Type { get; set; }
public string Label { get; set; }
public string Link { get; set; }
public TelegramLink(MetadataLinkType? type, string label, string link)
public NotificationMetadataLink(MetadataLinkType? type, string label, string link)
{
Type = type;
Label = label;

View file

@ -0,0 +1,45 @@
using System.Collections.Generic;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Notifications;
public static class NotificationMetadataLinkGenerator
{
public static List<NotificationMetadataLink> GenerateLinks(Series series, IEnumerable<int> metadataLinks)
{
var links = new List<NotificationMetadataLink>();
if (series == null)
{
return links;
}
foreach (var link in metadataLinks)
{
var linkType = (MetadataLinkType)link;
if (linkType == MetadataLinkType.Imdb && series.ImdbId.IsNotNullOrWhiteSpace())
{
links.Add(new NotificationMetadataLink(MetadataLinkType.Imdb, "IMDb", $"https://www.imdb.com/title/{series.ImdbId}"));
}
if (linkType == MetadataLinkType.Tvdb && series.TvdbId > 0)
{
links.Add(new NotificationMetadataLink(MetadataLinkType.Tvdb, "TVDb", $"http://www.thetvdb.com/?tab=series&id={series.TvdbId}"));
}
if (linkType == MetadataLinkType.Trakt && series.TvdbId > 0)
{
links.Add(new NotificationMetadataLink(MetadataLinkType.Trakt, "Trakt", $"http://trakt.tv/search/tvdb/{series.TvdbId}?id_type=show"));
}
if (linkType == MetadataLinkType.Tvmaze && series.TvMazeId > 0)
{
links.Add(new NotificationMetadataLink(MetadataLinkType.Tvmaze, "TVMaze", $"http://www.tvmaze.com/shows/{series.TvMazeId}/_"));
}
}
return links;
}
}

View file

@ -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.Pushcut
{
@ -28,52 +31,62 @@ namespace NzbDrone.Core.Notifications.Pushcut
public override void OnGrab(GrabMessage grabMessage)
{
_proxy.SendNotification(EPISODE_GRABBED_TITLE, grabMessage?.Message, Settings);
_proxy.SendNotification(EPISODE_GRABBED_TITLE, grabMessage?.Message, GetPosterUrl(grabMessage.Series), GetLinks(grabMessage.Series), Settings);
}
public override void OnDownload(DownloadMessage downloadMessage)
{
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE, downloadMessage.Message, Settings);
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE, downloadMessage.Message, GetPosterUrl(downloadMessage.Series), GetLinks(downloadMessage.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), GetLinks(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), GetLinks(deleteMessage.Series), Settings);
}
public override void OnSeriesAdd(SeriesAddMessage seriesAddMessage)
{
_proxy.SendNotification(SERIES_ADDED_TITLE, $"{seriesAddMessage.Series.Title} added to library", Settings);
_proxy.SendNotification(SERIES_ADDED_TITLE, $"{seriesAddMessage.Series.Title} added to library", GetPosterUrl(seriesAddMessage.Series), GetLinks(seriesAddMessage.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), GetLinks(deleteMessage.Series), Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE_BRANDED, healthCheck.Message, Settings);
_proxy.SendNotification(HEALTH_ISSUE_TITLE_BRANDED, healthCheck.Message, null, [], Settings);
}
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
{
_proxy.SendNotification(HEALTH_RESTORED_TITLE_BRANDED, $"The following issue is now resolved: {previousCheck.Message}", Settings);
_proxy.SendNotification(HEALTH_RESTORED_TITLE_BRANDED, $"The following issue is now resolved: {previousCheck.Message}", null, [], Settings);
}
public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
_proxy.SendNotification(APPLICATION_UPDATE_TITLE_BRANDED, updateMessage.Message, Settings);
_proxy.SendNotification(APPLICATION_UPDATE_TITLE_BRANDED, updateMessage.Message, null, [], Settings);
}
public override void OnManualInteractionRequired(ManualInteractionRequiredMessage manualInteractionRequiredMessage)
{
_proxy.SendNotification(MANUAL_INTERACTION_REQUIRED_TITLE_BRANDED, manualInteractionRequiredMessage.Message, Settings);
_proxy.SendNotification(MANUAL_INTERACTION_REQUIRED_TITLE_BRANDED, manualInteractionRequiredMessage.Message, null, [], Settings);
}
private string GetPosterUrl(Series series)
{
return series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.RemoteUrl;
}
private List<NotificationMetadataLink> GetLinks(Series series)
{
return NotificationMetadataLinkGenerator.GenerateLinks(series, Settings.MetadataLinks);
}
}
}

View file

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace NzbDrone.Core.Notifications.Pushcut
{
public class PushcutPayload
@ -5,5 +7,13 @@ namespace NzbDrone.Core.Notifications.Pushcut
public string Title { get; set; }
public string Text { get; set; }
public bool? IsTimeSensitive { get; set; }
public string Image { get; set; }
public List<PushcutAction> Actions;
}
public class PushcutAction
{
public string Name { get; set; }
public string Url { get; set; }
}
}

View file

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Notifications.Pushcut
{
public interface IPushcutProxy
{
void SendNotification(string title, string message, PushcutSettings settings);
void SendNotification(string title, string message, string posterUrl, List<NotificationMetadataLink> links, PushcutSettings settings);
ValidationFailure Test(PushcutSettings settings);
}
@ -29,20 +29,37 @@ namespace NzbDrone.Core.Notifications.Pushcut
_logger = logger;
}
public void SendNotification(string title, string message, PushcutSettings settings)
public void SendNotification(string title, string message, string posterUrl, List<NotificationMetadataLink> links, PushcutSettings settings)
{
if (settings == null)
{
return;
}
var request = new HttpRequestBuilder("https://api.pushcut.io/v1/notifications/{notificationName}")
.SetSegment("notificationName", settings?.NotificationName)
.SetHeader("API-Key", settings?.ApiKey)
.Accept(HttpAccept.Json)
.Build();
var payload = new PushcutPayload
{
Title = title,
Text = message,
IsTimeSensitive = settings?.TimeSensitive
Image = settings.IncludePoster ? posterUrl : null,
IsTimeSensitive = settings.TimeSensitive,
Actions = new List<PushcutAction>()
};
foreach (var link in links)
{
payload.Actions.Add(new PushcutAction
{
Name = link.Label,
Url = link.Link
});
}
request.Method = HttpMethod.Post;
request.Headers.ContentType = "application/json";
request.SetContent(payload.ToJson());
@ -64,7 +81,7 @@ namespace NzbDrone.Core.Notifications.Pushcut
{
const string title = "Sonarr Test Title";
const string message = "Success! You have properly configured your Pushcut notification settings.";
SendNotification(title, message, settings);
SendNotification(title, message, null, [], settings);
}
catch (PushcutException pushcutException) when (pushcutException.InnerException is HttpException httpException)
{

View file

@ -1,3 +1,4 @@
using System.Collections.Generic;
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Validation;
@ -26,6 +27,12 @@ namespace NzbDrone.Core.Notifications.Pushcut
[FieldDefinition(2, Label = "NotificationsPushcutSettingsTimeSensitive", Type = FieldType.Checkbox, HelpText = "NotificationsPushcutSettingsTimeSensitiveHelpText")]
public bool TimeSensitive { get; set; }
[FieldDefinition(3, Label = "NotificationsPushcutSettingsIncludePoster", Type = FieldType.Checkbox, HelpText = "NotificationsPushcutSettingsIncludePosterHelpText")]
public bool IncludePoster { get; set; }
[FieldDefinition(4, Label = "NotificationsPushcutSettingsMetadataLinks", Type = FieldType.Select, SelectOptions = typeof(MetadataLinkType), HelpText = "NotificationsPushcutSettingsMetadataLinksHelpText")]
public IEnumerable<int> MetadataLinks { get; set; } = [];
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));

View file

@ -81,7 +81,7 @@ namespace NzbDrone.Core.Notifications.Telegram
var title = Settings.IncludeAppNameInTitle ? HEALTH_ISSUE_TITLE_BRANDED : HEALTH_ISSUE_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, healthCheck.Message, new List<TelegramLink>(), Settings);
_proxy.SendNotification(title, healthCheck.Message, new List<NotificationMetadataLink>(), Settings);
}
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
@ -89,7 +89,7 @@ namespace NzbDrone.Core.Notifications.Telegram
var title = Settings.IncludeAppNameInTitle ? HEALTH_RESTORED_TITLE_BRANDED : HEALTH_RESTORED_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, $"The following issue is now resolved: {previousCheck.Message}", new List<TelegramLink>(), Settings);
_proxy.SendNotification(title, $"The following issue is now resolved: {previousCheck.Message}", new List<NotificationMetadataLink>(), Settings);
}
public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
@ -97,7 +97,7 @@ namespace NzbDrone.Core.Notifications.Telegram
var title = Settings.IncludeAppNameInTitle ? APPLICATION_UPDATE_TITLE_BRANDED : APPLICATION_UPDATE_TITLE;
title = Settings.IncludeInstanceNameInTitle ? $"{title} - {InstanceName}" : title;
_proxy.SendNotification(title, updateMessage.Message, new List<TelegramLink>(), Settings);
_proxy.SendNotification(title, updateMessage.Message, new List<NotificationMetadataLink>(), Settings);
}
public override void OnManualInteractionRequired(ManualInteractionRequiredMessage message)
@ -118,41 +118,9 @@ namespace NzbDrone.Core.Notifications.Telegram
return new ValidationResult(failures);
}
private List<TelegramLink> GetLinks(Series series)
private List<NotificationMetadataLink> GetLinks(Series series)
{
var links = new List<TelegramLink>();
if (series == null)
{
return links;
}
foreach (var link in Settings.MetadataLinks)
{
var linkType = (MetadataLinkType)link;
if (linkType == MetadataLinkType.Imdb && series.ImdbId.IsNotNullOrWhiteSpace())
{
links.Add(new TelegramLink(MetadataLinkType.Imdb, "IMDb", $"https://www.imdb.com/title/{series.ImdbId}"));
}
if (linkType == MetadataLinkType.Tvdb && series.TvdbId > 0)
{
links.Add(new TelegramLink(MetadataLinkType.Tvdb, "TVDb", $"http://www.thetvdb.com/?tab=series&id={series.TvdbId}"));
}
if (linkType == MetadataLinkType.Trakt && series.TvdbId > 0)
{
links.Add(new TelegramLink(MetadataLinkType.Trakt, "Trakt", $"http://trakt.tv/search/tvdb/{series.TvdbId}?id_type=show"));
}
if (linkType == MetadataLinkType.Tvmaze && series.TvMazeId > 0)
{
links.Add(new TelegramLink(MetadataLinkType.Tvmaze, "TVMaze", $"http://www.tvmaze.com/shows/{series.TvMazeId}/_"));
}
}
return links;
return NotificationMetadataLinkGenerator.GenerateLinks(series, Settings.MetadataLinks);
}
}
}

View file

@ -12,7 +12,7 @@ public class TelegramLinkPreviewOptions
[JsonProperty("url")]
public string Url { get; set; }
public TelegramLinkPreviewOptions(List<TelegramLink> links, TelegramSettings settings)
public TelegramLinkPreviewOptions(List<NotificationMetadataLink> links, TelegramSettings settings)
{
IsDisabled = (MetadataLinkPreviewType)settings.LinkPreview == MetadataLinkPreviewType.None;
Url = links.FirstOrDefault(l => l.Type.HasValue && (int)l.Type.Value == settings.LinkPreview)?.Link;

View file

@ -15,7 +15,7 @@ namespace NzbDrone.Core.Notifications.Telegram
{
public interface ITelegramProxy
{
void SendNotification(string title, string message, List<TelegramLink> links, TelegramSettings settings);
void SendNotification(string title, string message, List<NotificationMetadataLink> links, TelegramSettings settings);
ValidationFailure Test(TelegramSettings settings);
}
@ -36,7 +36,7 @@ namespace NzbDrone.Core.Notifications.Telegram
_logger = logger;
}
public void SendNotification(string title, string message, List<TelegramLink> links, TelegramSettings settings)
public void SendNotification(string title, string message, List<NotificationMetadataLink> links, TelegramSettings settings)
{
var text = new StringBuilder($"<b>{HttpUtility.HtmlEncode(title)}</b>\n");
@ -77,9 +77,9 @@ namespace NzbDrone.Core.Notifications.Telegram
const string title = "Test Notification";
const string body = "This is a test message from Sonarr";
var links = new List<TelegramLink>
var links = new List<NotificationMetadataLink>
{
new TelegramLink(null, "Sonarr.tv", "https://sonarr.tv")
new NotificationMetadataLink(null, "Sonarr.tv", "https://sonarr.tv")
};
var testMessageTitle = settings.IncludeAppNameInTitle ? brandedTitle : title;