ExternalNotifications enabled (Xbmc only right now).

- Grab, Download, Rename
Notification Settings for Xbmc uses definitions.
pull/2/head
Mark McDowall 13 years ago
parent 0ed898b6db
commit ee4b6c9442

@ -62,9 +62,9 @@ namespace NzbDrone.Core
_kernel.Get<QualityProvider>().SetupDefaultProfiles();
BindExternalNotifications();
BindIndexers();
BindJobs();
BindExternalNotifications();
}
private static void BindKernel()
@ -111,8 +111,9 @@ namespace NzbDrone.Core
private static void BindExternalNotifications()
{
_kernel.Bind<ExternalNotificationProviderBase>().To<XbmcNotificationProvider>().InSingletonScope();
var notifiers = _kernel.GetAll<ExternalNotificationProviderBase>();
_kernel.Bind<ExternalNotificationBase>().To<Xbmc>();
var notifiers = _kernel.GetAll<ExternalNotificationBase>();
_kernel.Get<ExternalNotificationProvider>().InitializeNotifiers(notifiers.ToList());
}

@ -0,0 +1,30 @@
using System;
using System.Data;
using Migrator.Framework;
namespace NzbDrone.Core.Datastore.Migrations
{
[Migration(20110726)]
public class Migration20110726 : Migration
{
public override void Up()
{
Database.RemoveTable("ExternalNotificationSettings");
Database.AddTable("ExternalNotificationDefinitions", new[]
{
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
new Column("Enable", DbType.Boolean, ColumnProperty.NotNull),
new Column("ExternalNotificationProviderType", DbType.String, ColumnProperty.NotNull),
new Column("Name", DbType.String, ColumnProperty.NotNull)
});
}
public override void Down()
{
throw new NotImplementedException();
}
}
}

@ -176,6 +176,7 @@
<Compile Include="Datastore\MigrationLogger.cs" />
<Compile Include="Datastore\MigrationsHelper.cs" />
<Compile Include="Datastore\CustomeMapper.cs" />
<Compile Include="Datastore\Migrations\Migration20110726.cs" />
<Compile Include="Datastore\Migrations\Migration20110707.cs" />
<Compile Include="Fluent.cs" />
<Compile Include="Helpers\EpisodeSortingHelper.cs" />
@ -203,8 +204,8 @@
<Compile Include="Model\Xbmc\VersionResult.cs" />
<Compile Include="Providers\DiskScanProvider.cs" />
<Compile Include="Providers\DownloadProvider.cs" />
<Compile Include="Providers\ExternalNotification\ExternalNotificationProviderBase.cs" />
<Compile Include="Providers\ExternalNotification\XbmcNotificationProvider.cs" />
<Compile Include="Providers\ExternalNotification\ExternalNotificationBase.cs" />
<Compile Include="Providers\ExternalNotification\Xbmc.cs" />
<Compile Include="Providers\InventoryProvider.cs" />
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" />
<Compile Include="Providers\AutoConfigureProvider.cs" />
@ -224,7 +225,7 @@
<Compile Include="Providers\Jobs\UpdateInfoJob.cs" />
<Compile Include="Providers\SceneMappingProvider.cs" />
<Compile Include="Providers\Xbmc\EventClientProvider.cs" />
<Compile Include="Repository\ExternalNotificationSetting.cs" />
<Compile Include="Repository\ExternalNotificationDefinition.cs" />
<Compile Include="Repository\JobDefinition.cs" />
<Compile Include="Repository\IndexerDefinition.cs" />
<Compile Include="Model\EpisodeParseResult.cs" />

@ -18,18 +18,22 @@ namespace NzbDrone.Core.Providers
private readonly EpisodeProvider _episodeProvider;
private readonly MediaFileProvider _mediaFileProvider;
private readonly SeriesProvider _seriesProvider;
private readonly ExternalNotificationProvider _externalNotificationProvider;
private readonly SabProvider _sabProvider;
[Inject]
public DiskScanProvider(DiskProvider diskProvider, EpisodeProvider episodeProvider,
SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider)
SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider,
ExternalNotificationProvider externalNotificationProvider, SabProvider sabProvider)
{
_diskProvider = diskProvider;
_episodeProvider = episodeProvider;
_seriesProvider = seriesProvider;
_mediaFileProvider = mediaFileProvider;
_externalNotificationProvider = externalNotificationProvider;
_sabProvider = sabProvider;
}
public DiskScanProvider()
{
}
@ -142,7 +146,7 @@ namespace NzbDrone.Core.Providers
return episodeFile;
}
public virtual bool MoveEpisodeFile(EpisodeFile episodeFile)
public virtual bool MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = false)
{
if (episodeFile == null)
throw new ArgumentNullException("episodeFile");
@ -163,6 +167,18 @@ namespace NzbDrone.Core.Providers
episodeFile.Path = newFile.FullName;
_mediaFileProvider.Update(episodeFile);
//ExternalNotification
var parseResult = Parser.ParsePath(episodeFile.Path);
parseResult.Series = series;
var message = _sabProvider.GetSabTitle(parseResult);
if (newDownload)
_externalNotificationProvider.OnDownload(message, series);
else
_externalNotificationProvider.OnRename(message, series);
return true;
}

@ -11,14 +11,18 @@ namespace NzbDrone.Core.Providers
private readonly SabProvider _sabProvider;
private readonly HistoryProvider _historyProvider;
private readonly EpisodeProvider _episodeProvider;
private readonly ExternalNotificationProvider _externalNotificationProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
[Inject]
public DownloadProvider(SabProvider sabProvider, HistoryProvider historyProvider, EpisodeProvider episodeProvider)
public DownloadProvider(SabProvider sabProvider, HistoryProvider historyProvider,
EpisodeProvider episodeProvider, ExternalNotificationProvider externalNotificationProvider)
{
_sabProvider = sabProvider;
_historyProvider = historyProvider;
_episodeProvider = episodeProvider;
_externalNotificationProvider = externalNotificationProvider;
}
public DownloadProvider()
@ -55,6 +59,8 @@ namespace NzbDrone.Core.Providers
}
}
_externalNotificationProvider.OnGrab(sabTitle);
return addSuccess;
}
}

@ -6,16 +6,14 @@ using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers.ExternalNotification
{
public abstract class ExternalNotificationProviderBase
public abstract class ExternalNotificationBase
{
protected readonly Logger _logger;
protected readonly ConfigProvider _configProvider;
protected readonly ExternalNotificationProvider _externalNotificationProvider;
protected ExternalNotificationProviderBase(ConfigProvider configProvider, ExternalNotificationProvider externalNotificationProvider)
protected ExternalNotificationBase(ConfigProvider configProvider)
{
_configProvider = configProvider;
_externalNotificationProvider = externalNotificationProvider;
_logger = LogManager.GetLogger(GetType().ToString());
}
@ -24,35 +22,6 @@ namespace NzbDrone.Core.Providers.ExternalNotification
/// </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)
{
throw new NotImplementedException();
var series = new Series();
OnDownload(message, series);
}
else if (type == ExternalNotificationType.Rename)
{
throw new NotImplementedException();
var series = new Series();
OnRename(message, series);
}
}
/// <summary>
/// Performs the on grab action
/// </summary>

@ -0,0 +1,66 @@
using System;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers.ExternalNotification
{
public class Xbmc : ExternalNotificationBase
{
private readonly XbmcProvider _xbmcProvider;
public Xbmc(ConfigProvider configProvider, XbmcProvider xbmcProvider)
: base(configProvider)
{
_xbmcProvider = xbmcProvider;
}
public override string Name
{
get { return "XBMC"; }
}
public override void OnGrab(string message)
{
const string header = "NzbDrone [TV] - Grabbed";
if (_configProvider.XbmcNotifyOnGrab)
{
_logger.Trace("Sending Notification to XBMC");
_xbmcProvider.Notify(header, message);
}
}
public override void OnDownload(string message, Series series)
{
const string header = "NzbDrone [TV] - Downloaded";
if (_configProvider.XbmcNotifyOnDownload)
{
_logger.Trace("Sending Notification to XBMC");
_xbmcProvider.Notify(header, message);
}
UpdateAndClean(series);
}
public override void OnRename(string message, Series series)
{
UpdateAndClean(series);
}
private void UpdateAndClean(Series series)
{
if (_configProvider.XbmcUpdateLibrary)
{
_logger.Trace("Sending Update Request to XBMC");
_xbmcProvider.Update(series);
}
if (_configProvider.XbmcCleanLibrary)
{
_logger.Trace("Sending Clean DB Request to XBMC");
_xbmcProvider.Clean();
}
}
}
}

@ -1,92 +0,0 @@
using System;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers.ExternalNotification
{
public class XbmcNotificationProvider : ExternalNotificationProviderBase
{
private readonly XbmcProvider _xbmcProvider;
public XbmcNotificationProvider(ConfigProvider configProvider, XbmcProvider xbmcProvider,
ExternalNotificationProvider externalNotificationProvider)
: base(configProvider, externalNotificationProvider)
{
_xbmcProvider = xbmcProvider;
}
public override string Name
{
get { return "XBMC"; }
}
public override void OnGrab(string message)
{
const string header = "NzbDrone [TV] - Grabbed";
if (Convert.ToBoolean(_configProvider.GetValue("XbmcEnabled", false)))
{
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnGrab", false)))
{
_logger.Trace("Sending Notification 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, Series series)
{
const string header = "NzbDrone [TV] - Downloaded";
if (Convert.ToBoolean(_configProvider.GetValue("XbmcEnabled", false)))
{
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnDownload", false)))
{
_logger.Trace("Sending Notification to XBMC");
_xbmcProvider.Notify(header, message);
}
if (Convert.ToBoolean(_configProvider.GetValue("XbmcUpdateOnDownload", false)))
{
_logger.Trace("Sending Update Request to XBMC");
_xbmcProvider.Update(series);
}
if (Convert.ToBoolean(_configProvider.GetValue("XbmcCleanOnDownload", false)))
{
_logger.Trace("Sending Clean DB Request to XBMC");
_xbmcProvider.Clean();
}
}
_logger.Trace("XBMC Notifier is not enabled");
}
public override void OnRename(string message, Series series)
{
const string header = "NzbDrone [TV] - Renamed";
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnRename", false)))
{
_logger.Trace("Sending Notification to XBMC");
_xbmcProvider.Notify(header, message);
}
if (Convert.ToBoolean(_configProvider.GetValue("XbmcUpdateOnRename", false)))
{
_logger.Trace("Sending Update Request to XBMC");
_xbmcProvider.Update(series);
}
if (Convert.ToBoolean(_configProvider.GetValue("XbmcCleanOnRename", false)))
{
_logger.Trace("Sending Clean DB Request to XBMC");
_xbmcProvider.Clean();
}
}
}
}

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Ninject;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.ExternalNotification;
using NzbDrone.Core.Repository;
using PetaPoco;
@ -13,10 +15,13 @@ namespace NzbDrone.Core.Providers
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IDatabase _database;
[Inject]
public ExternalNotificationProvider(IDatabase database)
private IEnumerable<ExternalNotificationBase> _notifiers;
[Inject]
public ExternalNotificationProvider(IDatabase database, IEnumerable<ExternalNotificationBase> notifiers)
{
_database = database;
_notifiers = notifiers;
}
public ExternalNotificationProvider()
@ -24,51 +29,54 @@ namespace NzbDrone.Core.Providers
}
public virtual List<ExternalNotificationSetting> All()
public virtual List<ExternalNotificationDefinition> All()
{
return _database.Fetch<ExternalNotificationSetting>();
return _database.Fetch<ExternalNotificationDefinition>();
}
public virtual void SaveSettings(ExternalNotificationSetting settings)
public virtual void SaveSettings(ExternalNotificationDefinition settings)
{
if (settings.Id == 0)
{
Logger.Debug("Adding External Notification settings for {0}", settings.Name);
Logger.Debug("Adding External Notification definition for {0}", settings.Name);
_database.Insert(settings);
}
else
{
Logger.Debug("Updating External Notification settings for {0}", settings.Name);
Logger.Debug("Updating External Notification definition for {0}", settings.Name);
_database.Update(settings);
}
}
public virtual ExternalNotificationSetting GetSettings(Type type)
public virtual ExternalNotificationDefinition GetSettings(Type type)
{
return _database.SingleOrDefault<ExternalNotificationSetting>("WHERE NotifierName = @0", type.ToString());
return _database.SingleOrDefault<ExternalNotificationDefinition>("WHERE ExternalNotificationProviderType = @0", type.ToString());
}
public virtual ExternalNotificationSetting GetSettings(int id)
public virtual IList<ExternalNotificationBase> GetEnabledExternalNotifiers()
{
return _database.SingleOrDefault<ExternalNotificationSetting>(id);
var all = All();
return _notifiers.Where(i => all.Exists(c => c.ExternalNotificationProviderType == i.GetType().ToString() && c.Enable)).ToList();
}
public virtual void InitializeNotifiers(IList<ExternalNotificationProviderBase> notifiers)
public virtual void InitializeNotifiers(IList<ExternalNotificationBase> notifiers)
{
Logger.Info("Initializing notifiers. Count {0}", notifiers.Count);
_notifiers = notifiers;
var currentNotifiers = All();
foreach (var feedProvider in notifiers)
foreach (var notificationProvider in notifiers)
{
ExternalNotificationProviderBase externalNotificationProviderLocal = feedProvider;
if (!currentNotifiers.Exists(c => c.NotifierName == externalNotificationProviderLocal.GetType().ToString()))
ExternalNotificationBase externalNotificationProviderLocal = notificationProvider;
if (!currentNotifiers.Exists(c => c.ExternalNotificationProviderType == externalNotificationProviderLocal.GetType().ToString()))
{
var settings = new ExternalNotificationSetting()
var settings = new ExternalNotificationDefinition
{
Enabled = false,
NotifierName = externalNotificationProviderLocal.GetType().ToString(),
Enable = false,
ExternalNotificationProviderType = externalNotificationProviderLocal.GetType().ToString(),
Name = externalNotificationProviderLocal.Name
};
@ -76,5 +84,29 @@ namespace NzbDrone.Core.Providers
}
}
}
public virtual void OnGrab(string message)
{
foreach (var notifier in _notifiers.Where(i => GetSettings(i.GetType()).Enable))
{
notifier.OnGrab(message);
}
}
public virtual void OnDownload(string message, Series series)
{
foreach (var notifier in _notifiers.Where(i => GetSettings(i.GetType()).Enable))
{
notifier.OnDownload(message, series);
}
}
public virtual void OnRename(string message, Series series)
{
foreach (var notifier in _notifiers.Where(i => GetSettings(i.GetType()).Enable))
{
notifier.OnRename(message, series);
}
}
}
}

@ -84,7 +84,7 @@ namespace NzbDrone.Core.Providers.Jobs
}
var importedFiles = _diskScanProvider.Scan(series, subfolder);
importedFiles.ForEach(file => _diskScanProvider.MoveEpisodeFile(file));
importedFiles.ForEach(file => _diskScanProvider.MoveEpisodeFile(file, true));
//Delete the folder only if folder is small enough
if (_diskProvider.GetDirectorySize(subfolder) < 10.Megabytes())

@ -0,0 +1,17 @@
using PetaPoco;
namespace NzbDrone.Core.Repository
{
[TableName("ExternalNotificationDefinitions")]
[PrimaryKey("Id", autoIncrement = true)]
public class ExternalNotificationDefinition
{
public int Id { get; set; }
public bool Enable { get; set; }
public string ExternalNotificationProviderType { get; set; }
public string Name { get; set; }
}
}

@ -1,17 +0,0 @@
using PetaPoco;
namespace NzbDrone.Core.Repository
{
[TableName("ExternalNotificationSettings")]
[PrimaryKey("Id", autoIncrement = true)]
public class ExternalNotificationSetting
{
public int Id { get; set; }
public bool Enabled { get; set; }
public string NotifierName { get; set; }
public string Name { get; set; }
}
}

@ -9,6 +9,7 @@ using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.ExternalNotification;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
@ -30,12 +31,15 @@ namespace NzbDrone.Web.Controllers
private readonly NotificationProvider _notificationProvider;
private readonly DiskProvider _diskProvider;
private readonly SeriesProvider _seriesProvider;
private readonly ExternalNotificationProvider _externalNotificationProvider;
public SettingsController(ConfigProvider configProvider, IndexerProvider indexerProvider,
QualityProvider qualityProvider, RootDirProvider rootDirProvider,
AutoConfigureProvider autoConfigureProvider, NotificationProvider notificationProvider,
DiskProvider diskProvider, SeriesProvider seriesProvider)
DiskProvider diskProvider, SeriesProvider seriesProvider,
ExternalNotificationProvider externalNotificationProvider)
{
_externalNotificationProvider = externalNotificationProvider;
_configProvider = configProvider;
_indexerProvider = indexerProvider;
_qualityProvider = qualityProvider;
@ -140,7 +144,7 @@ namespace NzbDrone.Web.Controllers
{
var model = new NotificationSettingsModel
{
XbmcEnabled = _configProvider.XbmcEnabled,
XbmcEnabled = _externalNotificationProvider.GetSettings(typeof(Xbmc)).Enable,
XbmcNotifyOnGrab = _configProvider.XbmcNotifyOnGrab,
XbmcNotifyOnDownload = _configProvider.XbmcNotifyOnDownload,
XbmcUpdateLibrary = _configProvider.XbmcUpdateLibrary,
@ -262,7 +266,6 @@ namespace NzbDrone.Web.Controllers
return new JsonResult { Data = "failed" };
}
}
[HttpPost]
public ActionResult SaveIndexers(IndexerSettingsModel data)
@ -395,7 +398,11 @@ namespace NzbDrone.Web.Controllers
if (ModelState.IsValid)
{
_configProvider.XbmcEnabled = data.XbmcEnabled;
//XBMC Enabled
var xbmcSettings = _externalNotificationProvider.GetSettings(typeof(Xbmc));
xbmcSettings.Enable = data.XbmcEnabled;
_externalNotificationProvider.SaveSettings(xbmcSettings);
_configProvider.XbmcNotifyOnGrab = data.XbmcNotifyOnGrab;
_configProvider.XbmcNotifyOnDownload = data.XbmcNotifyOnDownload;
_configProvider.XbmcUpdateLibrary = data.XbmcUpdateLibrary;

Loading…
Cancel
Save