mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 21:13:28 -07:00
New: Option to include series image for Gotify notifications
(cherry picked from commit e57e68c97a9d24f8344623ac8f731c2da220686b) Closes #3240
This commit is contained in:
parent
ecf63006f3
commit
150c76f61c
4 changed files with 120 additions and 19 deletions
|
@ -1,7 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NzbDrone.Core.MediaCover;
|
||||||
|
using NzbDrone.Core.Music;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Notifications.Gotify
|
namespace NzbDrone.Core.Notifications.Gotify
|
||||||
{
|
{
|
||||||
|
@ -21,47 +25,47 @@ namespace NzbDrone.Core.Notifications.Gotify
|
||||||
|
|
||||||
public override void OnGrab(GrabMessage grabMessage)
|
public override void OnGrab(GrabMessage grabMessage)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(ALBUM_GRABBED_TITLE, grabMessage.Message, Settings);
|
SendNotification(ALBUM_GRABBED_TITLE, grabMessage.Message, grabMessage.Artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnReleaseImport(AlbumDownloadMessage message)
|
public override void OnReleaseImport(AlbumDownloadMessage message)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(ALBUM_DOWNLOADED_TITLE, message.Message, Settings);
|
SendNotification(ALBUM_DOWNLOADED_TITLE, message.Message, message.Artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnAlbumDelete(AlbumDeleteMessage deleteMessage)
|
public override void OnAlbumDelete(AlbumDeleteMessage deleteMessage)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(ALBUM_DELETED_TITLE, deleteMessage.Message, Settings);
|
SendNotification(ALBUM_DELETED_TITLE, deleteMessage.Message, deleteMessage.Album?.Artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnArtistDelete(ArtistDeleteMessage deleteMessage)
|
public override void OnArtistDelete(ArtistDeleteMessage deleteMessage)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(ARTIST_DELETED_TITLE, deleteMessage.Message, Settings);
|
SendNotification(ARTIST_DELETED_TITLE, deleteMessage.Message, deleteMessage.Artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
|
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheck.Message, Settings);
|
SendNotification(HEALTH_ISSUE_TITLE, healthCheck.Message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
|
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(HEALTH_RESTORED_TITLE, $"The following issue is now resolved: {previousCheck.Message}", null);
|
SendNotification(HEALTH_RESTORED_TITLE, $"The following issue is now resolved: {previousCheck.Message}", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDownloadFailure(DownloadFailedMessage message)
|
public override void OnDownloadFailure(DownloadFailedMessage message)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(DOWNLOAD_FAILURE_TITLE, message.Message, Settings);
|
SendNotification(DOWNLOAD_FAILURE_TITLE, message.Message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnImportFailure(AlbumDownloadMessage message)
|
public override void OnImportFailure(AlbumDownloadMessage message)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(IMPORT_FAILURE_TITLE, message.Message, Settings);
|
SendNotification(IMPORT_FAILURE_TITLE, message.Message, message.Artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
|
public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
|
||||||
{
|
{
|
||||||
_proxy.SendNotification(APPLICATION_UPDATE_TITLE, updateMessage.Message, Settings);
|
SendNotification(APPLICATION_UPDATE_TITLE, updateMessage.Message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ValidationResult Test()
|
public override ValidationResult Test()
|
||||||
|
@ -70,10 +74,29 @@ namespace NzbDrone.Core.Notifications.Gotify
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var isMarkdown = false;
|
||||||
const string title = "Test Notification";
|
const string title = "Test Notification";
|
||||||
const string body = "This is a test message from Lidarr";
|
|
||||||
|
|
||||||
_proxy.SendNotification(title, body, Settings);
|
var sb = new StringBuilder();
|
||||||
|
sb.AppendLine("This is a test message from Lidarr");
|
||||||
|
|
||||||
|
if (Settings.IncludeArtistPoster)
|
||||||
|
{
|
||||||
|
isMarkdown = true;
|
||||||
|
|
||||||
|
sb.AppendLine("\r");
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = new GotifyMessage
|
||||||
|
{
|
||||||
|
Title = title,
|
||||||
|
Message = sb.ToString(),
|
||||||
|
Priority = Settings.Priority
|
||||||
|
};
|
||||||
|
|
||||||
|
payload.SetContentType(isMarkdown);
|
||||||
|
|
||||||
|
_proxy.SendNotification(payload, Settings);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -83,5 +106,35 @@ namespace NzbDrone.Core.Notifications.Gotify
|
||||||
|
|
||||||
return new ValidationResult(failures);
|
return new ValidationResult(failures);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SendNotification(string title, string message, Artist artist)
|
||||||
|
{
|
||||||
|
var isMarkdown = false;
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.AppendLine(message);
|
||||||
|
|
||||||
|
if (Settings.IncludeArtistPoster && artist != null)
|
||||||
|
{
|
||||||
|
var poster = artist.Metadata.Value.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.Url;
|
||||||
|
|
||||||
|
if (poster != null)
|
||||||
|
{
|
||||||
|
isMarkdown = true;
|
||||||
|
sb.AppendLine($"\r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = new GotifyMessage
|
||||||
|
{
|
||||||
|
Title = title,
|
||||||
|
Message = sb.ToString(),
|
||||||
|
Priority = Settings.Priority
|
||||||
|
};
|
||||||
|
|
||||||
|
payload.SetContentType(isMarkdown);
|
||||||
|
|
||||||
|
_proxy.SendNotification(payload, Settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
40
src/NzbDrone.Core/Notifications/Gotify/GotifyMessage.cs
Normal file
40
src/NzbDrone.Core/Notifications/Gotify/GotifyMessage.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Notifications.Gotify
|
||||||
|
{
|
||||||
|
public class GotifyMessage
|
||||||
|
{
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Message { get; set; }
|
||||||
|
public int Priority { get; set; }
|
||||||
|
public GotifyExtras Extras { get; set; }
|
||||||
|
|
||||||
|
public GotifyMessage()
|
||||||
|
{
|
||||||
|
Extras = new GotifyExtras();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetContentType(bool isMarkdown)
|
||||||
|
{
|
||||||
|
var contentType = isMarkdown ? "text/markdown" : "text/plain";
|
||||||
|
|
||||||
|
Extras.ClientDisplay = new GotifyClientDisplay(contentType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GotifyExtras
|
||||||
|
{
|
||||||
|
[JsonProperty("client::display")]
|
||||||
|
public GotifyClientDisplay ClientDisplay { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GotifyClientDisplay
|
||||||
|
{
|
||||||
|
public string ContentType { get; set; }
|
||||||
|
|
||||||
|
public GotifyClientDisplay(string contentType)
|
||||||
|
{
|
||||||
|
ContentType = contentType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,12 @@
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
|
using NzbDrone.Common.Serializer;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Notifications.Gotify
|
namespace NzbDrone.Core.Notifications.Gotify
|
||||||
{
|
{
|
||||||
public interface IGotifyProxy
|
public interface IGotifyProxy
|
||||||
{
|
{
|
||||||
void SendNotification(string title, string message, GotifySettings settings);
|
void SendNotification(GotifyMessage payload, GotifySettings settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GotifyProxy : IGotifyProxy
|
public class GotifyProxy : IGotifyProxy
|
||||||
|
@ -17,16 +18,20 @@ namespace NzbDrone.Core.Notifications.Gotify
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendNotification(string title, string message, GotifySettings settings)
|
public void SendNotification(GotifyMessage payload, GotifySettings settings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var request = new HttpRequestBuilder(settings.Server).Resource("message").Post()
|
var request = new HttpRequestBuilder(settings.Server)
|
||||||
.AddQueryParam("token", settings.AppToken)
|
.Resource("message")
|
||||||
.AddFormParameter("title", title)
|
.Post()
|
||||||
.AddFormParameter("message", message)
|
.AddQueryParam("token", settings.AppToken)
|
||||||
.AddFormParameter("priority", settings.Priority)
|
.Build();
|
||||||
.Build();
|
|
||||||
|
request.Headers.ContentType = "application/json";
|
||||||
|
|
||||||
|
var json = payload.ToJson();
|
||||||
|
request.SetContent(payload.ToJson());
|
||||||
|
|
||||||
_httpClient.Execute(request);
|
_httpClient.Execute(request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,9 @@ namespace NzbDrone.Core.Notifications.Gotify
|
||||||
[FieldDefinition(2, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(GotifyPriority), HelpText = "Priority of the notification")]
|
[FieldDefinition(2, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(GotifyPriority), HelpText = "Priority of the notification")]
|
||||||
public int Priority { get; set; }
|
public int Priority { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(3, Label = "Include Artist Poster", Type = FieldType.Checkbox, HelpText = "Include artist poster in message")]
|
||||||
|
public bool IncludeArtistPoster { get; set; }
|
||||||
|
|
||||||
public NzbDroneValidationResult Validate()
|
public NzbDroneValidationResult Validate()
|
||||||
{
|
{
|
||||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue