mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
Added ExternalNotificationProviderBase based on IndexProviderBase.
This commit is contained in:
parent
671dcd074c
commit
a36d5fae2f
16 changed files with 336 additions and 97 deletions
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Providers.ExternalNotification
|
||||
{
|
||||
public abstract class ExternalNotificationProviderBase
|
||||
{
|
||||
protected readonly Logger _logger;
|
||||
protected readonly ConfigProvider _configProvider;
|
||||
protected readonly ExternalNotificationProvider _externalNotificationProvider;
|
||||
|
||||
public ExternalNotificationProviderBase(ConfigProvider configProvider, ExternalNotificationProvider externalNotificationProvider)
|
||||
{
|
||||
_configProvider = configProvider;
|
||||
_externalNotificationProvider = externalNotificationProvider;
|
||||
_logger = LogManager.GetLogger(GetType().ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name for the notification provider
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
public ExternalNotificationSetting Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return _externalNotificationProvider.GetSettings(GetType());
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Notify(ExternalNotificationType type, string message, int seriesId = 0)
|
||||
{
|
||||
if (type == ExternalNotificationType.Grab)
|
||||
OnGrab(message);
|
||||
|
||||
else if (type == ExternalNotificationType.Download)
|
||||
OnDownload(message, seriesId);
|
||||
|
||||
else if (type == ExternalNotificationType.Rename)
|
||||
OnRename(message, seriesId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs the on grab action
|
||||
/// </summary>
|
||||
/// <param name = "message">The message to send to the receiver</param>
|
||||
public abstract void OnGrab(string message);
|
||||
|
||||
/// <summary>
|
||||
/// Performs the on download action
|
||||
/// </summary>
|
||||
/// <param name = "message">The message to send to the receiver</param>
|
||||
/// <param name = "seriesId">The Series ID for the new download</param>
|
||||
public abstract void OnDownload(string message, int seriesId);
|
||||
|
||||
/// <summary>
|
||||
/// Performs the on rename action
|
||||
/// </summary>
|
||||
/// <param name = "message">The message to send to the receiver</param>
|
||||
/// <param name = "seriesId">The Series ID for the new download</param>
|
||||
public abstract void OnRename(string message, int seriesId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Helpers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
|
||||
namespace NzbDrone.Core.Providers.ExternalNotification
|
||||
{
|
||||
public class XbmcNotificationProvider : ExternalNotificationProviderBase
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
private readonly XbmcProvider _xbmcProvider;
|
||||
|
||||
public XbmcNotificationProvider(ConfigProvider configProvider, XbmcProvider xbmcProvider,
|
||||
ExternalNotificationProvider externalNotificationProvider) : base(configProvider, externalNotificationProvider)
|
||||
{
|
||||
_xbmcProvider = xbmcProvider;
|
||||
_logger = LogManager.GetLogger(GetType().ToString());
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "XBMC"; }
|
||||
}
|
||||
|
||||
public override void OnGrab(string message)
|
||||
{
|
||||
var header = "NzbDrone [TV] - Grabbed";
|
||||
|
||||
if (Convert.ToBoolean(_configProvider.GetValue("XbmcEnabled", false, true)))
|
||||
{
|
||||
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnGrab", false, true)))
|
||||
{
|
||||
_logger.Trace("Sending Notifcation to XBMC");
|
||||
_xbmcProvider.Notify(header, message);
|
||||
return;
|
||||
}
|
||||
_logger.Trace("XBMC NotifyOnGrab is not enabled");
|
||||
}
|
||||
|
||||
_logger.Trace("XBMC Notifier is not enabled");
|
||||
}
|
||||
|
||||
public override void OnDownload(string message, int seriesId)
|
||||
{
|
||||
var header = "NzbDrone [TV] - Downloaded";
|
||||
|
||||
if (Convert.ToBoolean(_configProvider.GetValue("XbmcEnabled", false, true)))
|
||||
{
|
||||
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnDownload", false, true)))
|
||||
{
|
||||
_logger.Trace("Sending Notifcation to XBMC");
|
||||
_xbmcProvider.Notify(header, message);
|
||||
}
|
||||
|
||||
if (Convert.ToBoolean(_configProvider.GetValue("XbmcUpdateOnDownload", false, true)))
|
||||
{
|
||||
_logger.Trace("Sending Update Request to XBMC");
|
||||
_xbmcProvider.Update(seriesId);
|
||||
}
|
||||
|
||||
if (Convert.ToBoolean(_configProvider.GetValue("XbmcCleanOnDownload", false, true)))
|
||||
{
|
||||
_logger.Trace("Sending Clean DB Request to XBMC");
|
||||
_xbmcProvider.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Trace("XBMC Notifier is not enabled");
|
||||
}
|
||||
|
||||
public override void OnRename(string message, int seriesId)
|
||||
{
|
||||
var header = "NzbDrone [TV] - Renamed";
|
||||
|
||||
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnRename", false, true)))
|
||||
{
|
||||
_logger.Trace("Sending Notifcation to XBMC");
|
||||
_xbmcProvider.Notify(header, message);
|
||||
}
|
||||
|
||||
if (Convert.ToBoolean(_configProvider.GetValue("XbmcUpdateOnRename", false, true)))
|
||||
{
|
||||
_logger.Trace("Sending Update Request to XBMC");
|
||||
_xbmcProvider.Update(seriesId);
|
||||
}
|
||||
|
||||
if (Convert.ToBoolean(_configProvider.GetValue("XbmcCleanOnRename", false, true)))
|
||||
{
|
||||
_logger.Trace("Sending Clean DB Request to XBMC");
|
||||
_xbmcProvider.Clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue