You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.3 KiB
113 lines
3.3 KiB
using System.Collections.Generic;
|
|
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
|
|
{
|
|
public class Subsonic : NotificationBase<SubsonicSettings>
|
|
{
|
|
private readonly ISubsonicService _subsonicService;
|
|
private readonly Logger _logger;
|
|
|
|
public Subsonic(ISubsonicService subsonicService, Logger logger)
|
|
{
|
|
_subsonicService = subsonicService;
|
|
_logger = logger;
|
|
}
|
|
|
|
public override string Link => "http://subsonic.org/";
|
|
|
|
public override void OnGrab(GrabMessage grabMessage)
|
|
{
|
|
const string header = "Lidarr - Grabbed";
|
|
|
|
Notify(Settings, header, grabMessage.Message);
|
|
}
|
|
|
|
public override void OnReleaseImport(AlbumDownloadMessage message)
|
|
{
|
|
const string header = "Lidarr - Downloaded";
|
|
|
|
Notify(Settings, header, message.Message);
|
|
Update();
|
|
}
|
|
|
|
public override void OnRename(Artist artist, List<RenamedTrackFile> renamedFiles)
|
|
{
|
|
Update();
|
|
}
|
|
|
|
public override void OnArtistAdd(ArtistAddMessage message)
|
|
{
|
|
Notify(Settings, ARTIST_ADDED_TITLE_BRANDED, message.Message);
|
|
}
|
|
|
|
public override void OnArtistDelete(ArtistDeleteMessage deleteMessage)
|
|
{
|
|
Notify(Settings, ARTIST_DELETED_TITLE_BRANDED, deleteMessage.Message);
|
|
}
|
|
|
|
public override void OnAlbumDelete(AlbumDeleteMessage deleteMessage)
|
|
{
|
|
Notify(Settings, ALBUM_DELETED_TITLE_BRANDED, deleteMessage.Message);
|
|
}
|
|
|
|
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
|
|
{
|
|
Notify(Settings, HEALTH_ISSUE_TITLE_BRANDED, healthCheck.Message);
|
|
}
|
|
|
|
public override void OnTrackRetag(TrackRetagMessage message)
|
|
{
|
|
Notify(Settings, TRACK_RETAGGED_TITLE_BRANDED, message.Message);
|
|
}
|
|
|
|
public override string Name => "Subsonic";
|
|
|
|
public override ValidationResult Test()
|
|
{
|
|
var failures = new List<ValidationFailure>();
|
|
|
|
failures.AddIfNotNull(_subsonicService.Test(Settings, "Success! Subsonic has been successfully configured!"));
|
|
|
|
return new ValidationResult(failures);
|
|
}
|
|
|
|
private void Notify(SubsonicSettings settings, string header, string message)
|
|
{
|
|
try
|
|
{
|
|
if (Settings.Notify)
|
|
{
|
|
_subsonicService.Notify(Settings, $"{header} - {message}");
|
|
}
|
|
}
|
|
catch (SocketException ex)
|
|
{
|
|
var logMessage = $"Unable to connect to Subsonic Host: {Settings.Host}:{Settings.Port}";
|
|
_logger.Debug(ex, logMessage);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
try
|
|
{
|
|
if (Settings.UpdateLibrary)
|
|
{
|
|
_subsonicService.Update(Settings);
|
|
}
|
|
}
|
|
catch (SocketException ex)
|
|
{
|
|
var logMessage = $"Unable to connect to Subsonic Host: {Settings.Host}:{Settings.Port}";
|
|
_logger.Debug(ex, logMessage);
|
|
}
|
|
}
|
|
}
|
|
}
|