|
|
|
@ -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<NotifiarrSettings>
|
|
|
|
|
public class Notifiarr : WebhookBase<NotifiarrSettings>
|
|
|
|
|
{
|
|
|
|
|
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<RenamedTrackFile> 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<ValidationFailure>();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|