mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
ExternalNotifications, XBMC notification, building the framework for these, UI not implemented.
This commit is contained in:
parent
1314d00c97
commit
2af078b23d
@ -33,5 +33,27 @@ public static string GetSeasonFolder(int seasonNumber, string seasonFolderFormat
|
|||||||
{
|
{
|
||||||
return seasonFolderFormat.Replace("%s", seasonNumber.ToString()).Replace("%0s", seasonNumber.ToString("00"));
|
return seasonFolderFormat.Replace("%s", seasonNumber.ToString()).Replace("%0s", seasonNumber.ToString("00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetNameForNotify(EpisodeRenameModel erm)
|
||||||
|
{
|
||||||
|
if (erm.EpisodeFile.Episodes.Count == 1)
|
||||||
|
{
|
||||||
|
return String.Format("{0} - S{1:00}E{2:00} - {3}", erm.SeriesName,
|
||||||
|
erm.EpisodeFile.Episodes[0].SeasonNumber, erm.EpisodeFile.Episodes[0].EpisodeNumber,
|
||||||
|
erm.EpisodeFile.Episodes[0].Title);
|
||||||
|
}
|
||||||
|
|
||||||
|
var epNumberString = String.Empty;
|
||||||
|
var epNameString = String.Empty;
|
||||||
|
|
||||||
|
foreach (var episode in erm.EpisodeFile.Episodes)
|
||||||
|
{
|
||||||
|
epNumberString = epNumberString + String.Format("E{0:00}", episode.EpisodeNumber);
|
||||||
|
epNameString = epNameString + String.Format("+ {0}", episode.Title).Trim(' ', '+');
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.Format("{0} - S{1:00}E{2} - {3}", erm.SeriesName, erm.EpisodeFile.Episodes[0].SeasonNumber,
|
||||||
|
epNumberString, epNameString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
18
NzbDrone.Core/Helpers/ServerHelper.cs
Normal file
18
NzbDrone.Core/Helpers/ServerHelper.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Helpers
|
||||||
|
{
|
||||||
|
public static class ServerHelper
|
||||||
|
{
|
||||||
|
public static string GetServerHostname()
|
||||||
|
{
|
||||||
|
//Both these seem to return the same result... Is on better than the other?
|
||||||
|
return Environment.MachineName;
|
||||||
|
//return Dns.GetHostName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,5 +11,6 @@ public class EpisodeRenameModel
|
|||||||
public string SeriesName { get; set; }
|
public string SeriesName { get; set; }
|
||||||
public string Folder { get; set; }
|
public string Folder { get; set; }
|
||||||
public EpisodeFile EpisodeFile { get; set; }
|
public EpisodeFile EpisodeFile { get; set; }
|
||||||
|
public bool NewDownload { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
105
NzbDrone.Core/Providers/ExternalNotificationProvider.cs
Normal file
105
NzbDrone.Core/Providers/ExternalNotificationProvider.cs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Core.Helpers;
|
||||||
|
using NzbDrone.Core.Model;
|
||||||
|
using NzbDrone.Core.Repository;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Providers
|
||||||
|
{
|
||||||
|
public class ExternalNotificationProvider : IExtenalNotificationProvider
|
||||||
|
{
|
||||||
|
private readonly IConfigProvider _configProvider;
|
||||||
|
|
||||||
|
|
||||||
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
public ExternalNotificationProvider(IConfigProvider configProvider)
|
||||||
|
{
|
||||||
|
_configProvider = configProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IExternalNotificationProvider Members
|
||||||
|
public 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");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Logger.Trace("XBMC NotifyOnGrab is not enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Trace("XBMC Notifier is not enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDownload(EpisodeRenameModel erm)
|
||||||
|
{
|
||||||
|
var header = "NzbDrone [TV] - Downloaded";
|
||||||
|
var message = EpisodeRenameHelper.GetNewName(erm);
|
||||||
|
|
||||||
|
if (Convert.ToBoolean(_configProvider.GetValue("XbmcEnabled", false, true)))
|
||||||
|
{
|
||||||
|
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnDownload", false, true)))
|
||||||
|
{
|
||||||
|
Logger.Trace("Sending Notifcation to XBMC");
|
||||||
|
//Send to XBMC
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Convert.ToBoolean(_configProvider.GetValue("XbmcUpdateOnDownload", false, true)))
|
||||||
|
{
|
||||||
|
Logger.Trace("Sending Update Request to XBMC");
|
||||||
|
//Send to XBMC
|
||||||
|
//Send SeriesID
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Convert.ToBoolean(_configProvider.GetValue("XbmcCleanOnDownload", false, true)))
|
||||||
|
{
|
||||||
|
Logger.Trace("Sending Clean DB Request to XBMC");
|
||||||
|
//Send to XBMC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Trace("XBMC Notifier is not enabled");
|
||||||
|
|
||||||
|
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnRename(EpisodeRenameModel erm)
|
||||||
|
{
|
||||||
|
var header = "NzbDrone [TV] - Renamed";
|
||||||
|
var message = EpisodeRenameHelper.GetNewName(erm);
|
||||||
|
|
||||||
|
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnRename", false, true)))
|
||||||
|
{
|
||||||
|
Logger.Trace("Sending Notifcation to XBMC");
|
||||||
|
//Send to XBMC
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Convert.ToBoolean(_configProvider.GetValue("XbmcUpdateOnRename", false, true)))
|
||||||
|
{
|
||||||
|
Logger.Trace("Sending Update Request to XBMC");
|
||||||
|
//Send to XBMC
|
||||||
|
//Send SeriesID
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Convert.ToBoolean(_configProvider.GetValue("XbmcCleanOnRename", false, true)))
|
||||||
|
{
|
||||||
|
Logger.Trace("Sending Clean DB Request to XBMC");
|
||||||
|
//Send to XBMC
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
15
NzbDrone.Core/Providers/IExtenalNotificationProvider.cs
Normal file
15
NzbDrone.Core/Providers/IExtenalNotificationProvider.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using NzbDrone.Core.Repository;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Providers
|
||||||
|
{
|
||||||
|
public interface IExtenalNotificationProvider
|
||||||
|
{
|
||||||
|
void OnGrab(string message);
|
||||||
|
void OnDownload(EpisodeFile episodeFile);
|
||||||
|
void OnRename(EpisodeFile episodeFile);
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,6 @@ public interface IRenameProvider
|
|||||||
void RenameSeries(int seriesId);
|
void RenameSeries(int seriesId);
|
||||||
void RenameSeason(int seasonId);
|
void RenameSeason(int seasonId);
|
||||||
void RenameEpisode(int episodeId);
|
void RenameEpisode(int episodeId);
|
||||||
void RenameEpisodeFile(int episodeFileId);
|
void RenameEpisodeFile(int episodeFileId, bool newDownload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
NzbDrone.Core/Providers/IXbmcProvider.cs
Normal file
14
NzbDrone.Core/Providers/IXbmcProvider.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Providers
|
||||||
|
{
|
||||||
|
public interface IXbmcProvider
|
||||||
|
{
|
||||||
|
void Notify(string header, string message);
|
||||||
|
void Update(int seriesId);
|
||||||
|
void Clean();
|
||||||
|
}
|
||||||
|
}
|
@ -40,7 +40,7 @@ public void ProcessEpisode(string dir, string nzbName)
|
|||||||
foreach (var file in fileList)
|
foreach (var file in fileList)
|
||||||
{
|
{
|
||||||
//Todo: Where should we handle XBMC notifying/library updating etc? RenameProvider seems like a likely place, since we want to update XBMC after renaming (might as well)
|
//Todo: Where should we handle XBMC notifying/library updating etc? RenameProvider seems like a likely place, since we want to update XBMC after renaming (might as well)
|
||||||
_renameProvider.RenameEpisodeFile(file.EpisodeFileId);
|
_renameProvider.RenameEpisodeFile(file.EpisodeFileId, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ public class RenameProvider : IRenameProvider
|
|||||||
private readonly IMediaFileProvider _mediaFileProvider;
|
private readonly IMediaFileProvider _mediaFileProvider;
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
private readonly IConfigProvider _configProvider;
|
private readonly IConfigProvider _configProvider;
|
||||||
|
private readonly IExtenalNotificationProvider _externalNotificationProvider;
|
||||||
|
|
||||||
private Thread _renameThread;
|
private Thread _renameThread;
|
||||||
private List<EpisodeRenameModel> _epsToRename = new List<EpisodeRenameModel>();
|
private List<EpisodeRenameModel> _epsToRename = new List<EpisodeRenameModel>();
|
||||||
|
|
||||||
@ -26,7 +28,8 @@ public class RenameProvider : IRenameProvider
|
|||||||
|
|
||||||
public RenameProvider(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider,
|
public RenameProvider(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider,
|
||||||
IEpisodeProvider episodeProvider, IMediaFileProvider mediaFileProvider,
|
IEpisodeProvider episodeProvider, IMediaFileProvider mediaFileProvider,
|
||||||
IDiskProvider diskProvider, IConfigProvider configProvider)
|
IDiskProvider diskProvider, IConfigProvider configProvider,
|
||||||
|
IExtenalNotificationProvider extenalNotificationProvider)
|
||||||
{
|
{
|
||||||
_seriesProvider = seriesProvider;
|
_seriesProvider = seriesProvider;
|
||||||
_seasonProvider = seasonProvider;
|
_seasonProvider = seasonProvider;
|
||||||
@ -34,6 +37,7 @@ public RenameProvider(ISeriesProvider seriesProvider, ISeasonProvider seasonProv
|
|||||||
_mediaFileProvider = mediaFileProvider;
|
_mediaFileProvider = mediaFileProvider;
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
_configProvider = configProvider;
|
_configProvider = configProvider;
|
||||||
|
_externalNotificationProvider = extenalNotificationProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IRenameProvider Members
|
#region IRenameProvider Members
|
||||||
@ -122,7 +126,7 @@ public void RenameEpisode(int episodeId)
|
|||||||
StartRename();
|
StartRename();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenameEpisodeFile(int episodeFileId)
|
public void RenameEpisodeFile(int episodeFileId, bool newDownload)
|
||||||
{
|
{
|
||||||
//This will properly rename multi-episode files if asked to rename either of the episode
|
//This will properly rename multi-episode files if asked to rename either of the episode
|
||||||
var episodeFile = _mediaFileProvider.GetEpisodeFile(episodeFileId);
|
var episodeFile = _mediaFileProvider.GetEpisodeFile(episodeFileId);
|
||||||
@ -193,6 +197,12 @@ private void RenameFile(EpisodeRenameModel erm)
|
|||||||
erm.EpisodeFile.Path = newFilename;
|
erm.EpisodeFile.Path = newFilename;
|
||||||
_mediaFileProvider.Update(erm.EpisodeFile);
|
_mediaFileProvider.Update(erm.EpisodeFile);
|
||||||
|
|
||||||
|
if (erm.NewDownload)
|
||||||
|
_externalNotificationProvider.OnDownload();
|
||||||
|
|
||||||
|
else
|
||||||
|
_externalNotificationProvider.OnRename();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
79
NzbDrone.Core/Providers/XbmcProvider.cs
Normal file
79
NzbDrone.Core/Providers/XbmcProvider.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Providers
|
||||||
|
{
|
||||||
|
public class XbmcProvider : IXbmcProvider
|
||||||
|
{
|
||||||
|
private readonly IConfigProvider _configProvider;
|
||||||
|
|
||||||
|
private WebClient _webClient;
|
||||||
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
public XbmcProvider(IConfigProvider configProvider)
|
||||||
|
{
|
||||||
|
_webClient = new WebClient();
|
||||||
|
_configProvider = configProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IXbmcProvider Members
|
||||||
|
|
||||||
|
public void Notify(string header, string message)
|
||||||
|
{
|
||||||
|
//Get time in seconds and convert to ms
|
||||||
|
var time = Convert.ToInt32(_configProvider.GetValue("XbmcDisplayTime", "3", true)) * 1000;
|
||||||
|
|
||||||
|
var command = String.Format("ExecBuiltIn(Notification({0},{1},{2}))", header, message, time);
|
||||||
|
|
||||||
|
foreach (var host in _configProvider.GetValue("XbmcHosts", "localhost:80", true).Split(','))
|
||||||
|
{
|
||||||
|
Logger.Trace("Sending Notifcation to XBMC Host: {0}", host);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(int seriesId)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clean()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private string SendCommand(string host, string command)
|
||||||
|
{
|
||||||
|
var username = _configProvider.GetValue("XbmcUsername", String.Empty, true);
|
||||||
|
var password = _configProvider.GetValue("XbmcPassword", String.Empty, true);
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(username))
|
||||||
|
{
|
||||||
|
_webClient.Credentials = new NetworkCredential(username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
var url = String.Format("http://{0}/xbmcCmds/xbmcHttp?command={1}", host, command);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _webClient.DownloadString(url);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Warn("Unable to Connect to XBMC Host: {0}", host);
|
||||||
|
Logger.DebugException(ex.Message, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
NzbDrone.Web/Content/XbmcNotification.png
Normal file
BIN
NzbDrone.Web/Content/XbmcNotification.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.1 KiB |
@ -1,27 +0,0 @@
|
|||||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NzbDrone.Web.Models.SettingsModel>" %>
|
|
||||||
|
|
||||||
<%@ Import Namespace="NzbDrone.Web.Controllers" %>
|
|
||||||
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
|
|
||||||
Settings
|
|
||||||
</asp:Content>
|
|
||||||
<asp:Content ID="General" ContentPlaceHolderID="MainContent" runat="server">
|
|
||||||
<% using (Html.BeginForm())
|
|
||||||
{ %>
|
|
||||||
<%: Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.") %>
|
|
||||||
<div>
|
|
||||||
<fieldset>
|
|
||||||
<legend>General</legend>
|
|
||||||
<div class="editor-label">
|
|
||||||
<%: Html.LabelFor(m => m.TvFolder) %>
|
|
||||||
</div>
|
|
||||||
<div class="editor-field">
|
|
||||||
<%: Html.TextBoxFor(m => m.TvFolder) %>
|
|
||||||
<%: Html.ValidationMessageFor(m => m.TvFolder) %>
|
|
||||||
</div>
|
|
||||||
<p>
|
|
||||||
<input type="submit" value="Save" />
|
|
||||||
</p>
|
|
||||||
</fieldset>
|
|
||||||
</div>
|
|
||||||
<% } %>
|
|
||||||
</asp:Content>
|
|
Loading…
Reference in New Issue
Block a user