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.
114 lines
3.4 KiB
114 lines
3.4 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
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.Xbmc
|
|
{
|
|
public class Xbmc : NotificationBase<XbmcSettings>
|
|
{
|
|
private readonly IXbmcService _xbmcService;
|
|
private readonly Logger _logger;
|
|
|
|
public Xbmc(IXbmcService xbmcService, Logger logger)
|
|
{
|
|
_xbmcService = xbmcService;
|
|
_logger = logger;
|
|
}
|
|
|
|
public override string Link => "https://kodi.tv";
|
|
|
|
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);
|
|
UpdateAndClean(message.Artist, message.OldFiles.Any());
|
|
}
|
|
|
|
public override void OnRename(Artist artist, List<RenamedTrackFile> renamedFiles)
|
|
{
|
|
UpdateAndClean(artist);
|
|
}
|
|
|
|
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
|
|
{
|
|
Notify(Settings, HEALTH_ISSUE_TITLE_BRANDED, healthCheck.Message);
|
|
}
|
|
|
|
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
|
|
{
|
|
Notify(Settings, HEALTH_RESTORED_TITLE_BRANDED, $"The following issue is now resolved: {previousCheck.Message}");
|
|
}
|
|
|
|
public override void OnTrackRetag(TrackRetagMessage message)
|
|
{
|
|
UpdateAndClean(message.Artist);
|
|
}
|
|
|
|
public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
|
|
{
|
|
Notify(Settings, APPLICATION_UPDATE_TITLE_BRANDED, updateMessage.Message);
|
|
}
|
|
|
|
public override string Name => "Kodi";
|
|
|
|
public override ValidationResult Test()
|
|
{
|
|
var failures = new List<ValidationFailure>();
|
|
|
|
failures.AddIfNotNull(_xbmcService.Test(Settings, "Success! Kodi has been successfully configured!"));
|
|
|
|
return new ValidationResult(failures);
|
|
}
|
|
|
|
private void Notify(XbmcSettings settings, string header, string message)
|
|
{
|
|
try
|
|
{
|
|
if (Settings.Notify)
|
|
{
|
|
_xbmcService.Notify(Settings, header, message);
|
|
}
|
|
}
|
|
catch (SocketException ex)
|
|
{
|
|
var logMessage = string.Format("Unable to connect to Kodi Host: {0}:{1}", Settings.Host, Settings.Port);
|
|
_logger.Debug(ex, logMessage);
|
|
}
|
|
}
|
|
|
|
private void UpdateAndClean(Artist artist, bool clean = true)
|
|
{
|
|
try
|
|
{
|
|
if (Settings.UpdateLibrary)
|
|
{
|
|
_xbmcService.Update(Settings, artist);
|
|
}
|
|
|
|
if (clean && Settings.CleanLibrary)
|
|
{
|
|
_xbmcService.Clean(Settings);
|
|
}
|
|
}
|
|
catch (SocketException ex)
|
|
{
|
|
var logMessage = string.Format("Unable to connect to Kodi Host: {0}:{1}", Settings.Host, Settings.Port);
|
|
_logger.Debug(ex, logMessage);
|
|
}
|
|
}
|
|
}
|
|
}
|