From 54c29ada1246c26a9e023c52b4f6ce878d00f5f3 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 23 Jan 2013 23:31:41 -0800 Subject: [PATCH] Nzbget added to UI #ND-145 fixed --- .../Providers/Core/ConfigProvider.cs | 2 +- .../DownloadClients/NzbgetProvider.cs | 8 +-- NzbDrone.Core/Providers/DownloadProvider.cs | 8 ++- NzbDrone.Web/Controllers/CommandController.cs | 16 +++++- .../Controllers/SettingsController.cs | 26 +++++++++- .../Models/DownloadClientSettingsModel.cs | 46 ++++++++++++++++- NzbDrone.Web/NzbDrone.Web.csproj | 1 + NzbDrone.Web/Scripts/NzbDrone/settings.js | 14 ++++++ .../Views/Settings/DownloadClient.cshtml | 3 ++ NzbDrone.Web/Views/Settings/Nzbget.cshtml | 50 +++++++++++++++++++ NzbDrone.Web/Views/Settings/Sabnzbd.cshtml | 4 +- 11 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 NzbDrone.Web/Views/Settings/Nzbget.cshtml diff --git a/NzbDrone.Core/Providers/Core/ConfigProvider.cs b/NzbDrone.Core/Providers/Core/ConfigProvider.cs index a917eb20d..8b8ee6f01 100644 --- a/NzbDrone.Core/Providers/Core/ConfigProvider.cs +++ b/NzbDrone.Core/Providers/Core/ConfigProvider.cs @@ -558,7 +558,7 @@ namespace NzbDrone.Core.Providers.Core public virtual String NzbgetHost { - get { return GetValue("NzbgetHost", "nzbget"); } + get { return GetValue("NzbgetHost", "localhost"); } set { SetValue("NzbgetHost", value); } } diff --git a/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs b/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs index 43a4bb7dc..70c80358f 100644 --- a/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs +++ b/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs @@ -131,15 +131,15 @@ namespace NzbDrone.Core.Providers.DownloadClients Params = null }; - var url = String.Format(@"http://{0}:{1}/jsonrpc", host, port); - var response = _httpProvider.PostCommand(url, username, password, JsonConvert.SerializeObject(command)); + var address = String.Format(@"{0}:{1}", host, port); + var response = _httpProvider.PostCommand(address, username, password, JsonConvert.SerializeObject(command)); CheckForError(response); return JsonConvert.DeserializeObject(response); } - public virtual string Test(string host, int port, string apiKey, string username, string password) + public virtual string Test(string host, int port, string username, string password) { try { @@ -156,7 +156,7 @@ namespace NzbDrone.Core.Providers.DownloadClients private string PostCommand(string command) { - var url = String.Format(@"http://{0}:{1}/jsonrpc", + var url = String.Format(@"{0}:{1}", _configProvider.NzbgetHost, _configProvider.NzbgetPort); diff --git a/NzbDrone.Core/Providers/DownloadProvider.cs b/NzbDrone.Core/Providers/DownloadProvider.cs index 25302e826..aaef0e24f 100644 --- a/NzbDrone.Core/Providers/DownloadProvider.cs +++ b/NzbDrone.Core/Providers/DownloadProvider.cs @@ -19,13 +19,15 @@ namespace NzbDrone.Core.Providers private readonly BlackholeProvider _blackholeProvider; private readonly SignalRProvider _signalRProvider; private readonly PneumaticProvider _pneumaticProvider; + private readonly NzbgetProvider _nzbgetProvider; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); public DownloadProvider(SabProvider sabProvider, HistoryProvider historyProvider, EpisodeProvider episodeProvider, ExternalNotificationProvider externalNotificationProvider, ConfigProvider configProvider, BlackholeProvider blackholeProvider, - SignalRProvider signalRProvider, PneumaticProvider pneumaticProvider) + SignalRProvider signalRProvider, PneumaticProvider pneumaticProvider, + NzbgetProvider nzbgetProvider) { _sabProvider = sabProvider; _historyProvider = historyProvider; @@ -35,6 +37,7 @@ namespace NzbDrone.Core.Providers _blackholeProvider = blackholeProvider; _signalRProvider = signalRProvider; _pneumaticProvider = pneumaticProvider; + _nzbgetProvider = nzbgetProvider; } public DownloadProvider() @@ -90,6 +93,9 @@ namespace NzbDrone.Core.Providers case DownloadClientType.Pneumatic: return _pneumaticProvider; + case DownloadClientType.Nzbget: + return _nzbgetProvider; + default: return _sabProvider; } diff --git a/NzbDrone.Web/Controllers/CommandController.cs b/NzbDrone.Web/Controllers/CommandController.cs index 1bfe2ee50..1b9c7b11b 100644 --- a/NzbDrone.Web/Controllers/CommandController.cs +++ b/NzbDrone.Web/Controllers/CommandController.cs @@ -21,6 +21,7 @@ namespace NzbDrone.Web.Controllers private readonly ProwlProvider _prowlProvider; private readonly XbmcProvider _xbmcProvider; private readonly PlexProvider _plexProvider; + private readonly NzbgetProvider _nzbgetProvider; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); @@ -28,7 +29,8 @@ namespace NzbDrone.Web.Controllers SmtpProvider smtpProvider, TwitterProvider twitterProvider, EpisodeProvider episodeProvider, GrowlProvider growlProvider, SeasonProvider seasonProvider, ProwlProvider prowlProvider, - XbmcProvider xbmcProvider, PlexProvider plexProvider) + XbmcProvider xbmcProvider, PlexProvider plexProvider, + NzbgetProvider nzbgetProvider) { _jobProvider = jobProvider; _sabProvider = sabProvider; @@ -40,6 +42,7 @@ namespace NzbDrone.Web.Controllers _prowlProvider = prowlProvider; _xbmcProvider = xbmcProvider; _plexProvider = plexProvider; + _nzbgetProvider = nzbgetProvider; } public JsonResult RssSync() @@ -174,6 +177,17 @@ namespace NzbDrone.Web.Controllers return JsonNotificationResult.Info("Success!", "SABnzbd settings have been verified successfully! Version: " + version); } + public JsonResult TestNzbget(string host, int port, string username, string password) + { + //_prowlProvider.TestNotification(apiKeys); + var version = _nzbgetProvider.Test(host, port, username, password); + + if (String.IsNullOrWhiteSpace(version)) + return JsonNotificationResult.Oops("Failed to connect to Nzbget, please check your settings"); + + return JsonNotificationResult.Info("Success!", "Nzbget settings have been verified successfully! Version: " + version); + } + public JsonResult TestXbmcNotification(string hosts) { try diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 4dd65c053..e2bb6a921 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -8,6 +8,7 @@ using NzbDrone.Common.Model; using NzbDrone.Core.Helpers; using NzbDrone.Core.Jobs; using NzbDrone.Core.Model; +using NzbDrone.Core.Model.Nzbget; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.ExternalNotification; @@ -145,9 +146,25 @@ namespace NzbDrone.Web.Controllers BlackholeDirectory = _configProvider.BlackholeDirectory, DownloadClientSelectList = new SelectList(downloadClientTypes, "Key", "Value"), PneumaticDirectory = _configProvider.PneumaticDirectory, - UseSceneName = _configProvider.DownloadClientUseSceneName + UseSceneName = _configProvider.DownloadClientUseSceneName, + NzbgetHost = _configProvider.NzbgetHost, + NzbgetPort = _configProvider.NzbgetPort, + NzbgetUsername = _configProvider.NzbgetUsername, + NzbgetPassword = _configProvider.NzbgetPassword, + NzbgetTvCategory = _configProvider.NzbgetTvCategory, + NzbgetBacklogTvPriority = (Int32)_configProvider.NzbgetBacklogTvPriority, + NzbgetRecentTvPriority = (Int32)_configProvider.NzbgetRecentTvPriority }; + model.NzbgetPrioritySelectList = new SelectList(new List + { + new { Key = "Very Low", Value = "-100" }, + new { Key = "Low", Value = "-50" }, + new { Key = "Normal", Value = "0" }, + new { Key = "High", Value = "-50" }, + new { Key = "Very High", Value = "100" } + }, "Value", "Key"); + return View(model); } @@ -460,6 +477,13 @@ namespace NzbDrone.Web.Controllers _configProvider.DownloadClient = (DownloadClientType)data.DownloadClient; _configProvider.PneumaticDirectory = data.PneumaticDirectory; _configProvider.DownloadClientUseSceneName = data.UseSceneName; + _configProvider.NzbgetHost = data.NzbgetHost; + _configProvider.NzbgetPort = data.NzbgetPort; + _configProvider.NzbgetUsername = data.NzbgetUsername; + _configProvider.NzbgetPassword = data.NzbgetPassword; + _configProvider.NzbgetTvCategory = data.NzbgetTvCategory; + _configProvider.NzbgetBacklogTvPriority = (PriorityType)data.NzbgetBacklogTvPriority; + _configProvider.NzbgetRecentTvPriority = (PriorityType)data.NzbgetRecentTvPriority; return GetSuccessResult(); } diff --git a/NzbDrone.Web/Models/DownloadClientSettingsModel.cs b/NzbDrone.Web/Models/DownloadClientSettingsModel.cs index b15ff3988..461bec34c 100644 --- a/NzbDrone.Web/Models/DownloadClientSettingsModel.cs +++ b/NzbDrone.Web/Models/DownloadClientSettingsModel.cs @@ -1,8 +1,10 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Web.Mvc; using NzbDrone.Core.Model; +using NzbDrone.Core.Model.Nzbget; using NzbDrone.Core.Model.Sabnzbd; using NzbDrone.Web.Helpers.Validation; @@ -10,9 +12,11 @@ namespace NzbDrone.Web.Models { public class DownloadClientSettingsModel { - public SelectList PrioritySelectList = + public SelectList SabPrioritySelectList = new SelectList(new[] {"Default", "Paused", "Low", "Normal", "High", "Force"}); + public SelectList NzbgetPrioritySelectList { get; set; } + [DataType(DataType.Text)] [DisplayName("SABnzbd Host")] [Description("Hostname or IP Address running SABnzbd")] @@ -85,6 +89,46 @@ namespace NzbDrone.Web.Models [Description("Use Scene name when adding NZB to queue?")] public Boolean UseSceneName { get; set; } + [DataType(DataType.Text)] + [DisplayName("Nzbget Host")] + [Description("Hostname or IP Address running Nzbget")] + [RequiredIf("DownloadClient", (int)DownloadClientType.Nzbget, ErrorMessage = "Required when Download Client is Nzbget")] + public String NzbgetHost { get; set; } + + [DataType(DataType.Text)] + [DisplayName("Nzbget Port")] + [Description("Port for Nzbget web interface")] + [RequiredIf("DownloadClient", (int)DownloadClientType.Nzbget, ErrorMessage = "Required when Download Client is Nzbget")] + public int NzbgetPort { get; set; } + + [DataType(DataType.Text)] + [DisplayName("Nzbget Username")] + [Description("Username for Nzbget")] + [DisplayFormat(ConvertEmptyStringToNull = false)] + public String NzbgetUsername { get; set; } + + [DataType(DataType.Text)] + [DisplayName("Nzbget Password")] + [Description("Password for Nzbget")] + [DisplayFormat(ConvertEmptyStringToNull = false)] + public String NzbgetPassword { get; set; } + + [DataType(DataType.Text)] + [DisplayFormat(ConvertEmptyStringToNull = false)] + [DisplayName("Nzbget TV Category")] + [Description("Category to use when sending NZBs to Nzbget")] + public String NzbgetTvCategory { get; set; } + + [Required(ErrorMessage = "Please select a valid priority")] + [DisplayName("Nzbget Backlog Priority")] + [Description("Priority to use when sending episodes older than 7 days to Nzbget")] + public Int32 NzbgetBacklogTvPriority { get; set; } + + [Required(ErrorMessage = "Please select a valid priority")] + [DisplayName("Nzbget Recent Priority")] + [Description("Priority to use when sending episodes newer than 7 days to Nzbget")] + public Int32 NzbgetRecentTvPriority { get; set; } + public SelectList SabTvCategorySelectList { get; set; } public SelectList DownloadClientSelectList { get; set; } } diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 92127348c..1d00a3a13 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -305,6 +305,7 @@ + diff --git a/NzbDrone.Web/Scripts/NzbDrone/settings.js b/NzbDrone.Web/Scripts/NzbDrone/settings.js index 5791544bf..cca8c71a1 100644 --- a/NzbDrone.Web/Scripts/NzbDrone/settings.js +++ b/NzbDrone.Web/Scripts/NzbDrone/settings.js @@ -8,6 +8,7 @@ $('#MultiEpisodeStyle').live('change', function () { createExamples(); }); var testProwlUrl = '../Command/TestProwl'; var testSabUrl = '../Command/TestSabnzbd'; +var testNzbgetUrl = '../Command/TestNzbget'; var testEmailUrl = '../Command/TestEmail'; var testXbmcNotificationUrl = '../Command/TestXbmcNotification'; var testXbmcJsonApiUrl = '../Command/TestXbmcJsonApi'; @@ -145,6 +146,19 @@ function testSabnzbd(event) { event.preventDefault(); } +function testNzbget() { + var host = $('#NzbgetHost').val(); + var port = $('#NzbgetPort').val(); + var username = $('#NzbgetUsername').val(); + var password = $('#NzbgetPassword').val(); + + $.ajax({ + type: "GET", + url: testNzbgetUrl, + data: jQuery.param({ host: host, port: port, username: username, password: password }) + }); +} + //Twitter getAuthorizationUrl = '../Command/GetTwitterAuthorization'; verifyAuthorizationUrl = '../Command/VerifyTwitterAuthorization'; diff --git a/NzbDrone.Web/Views/Settings/DownloadClient.cshtml b/NzbDrone.Web/Views/Settings/DownloadClient.cshtml index 0591e15f4..3ce526b9c 100644 --- a/NzbDrone.Web/Views/Settings/DownloadClient.cshtml +++ b/NzbDrone.Web/Views/Settings/DownloadClient.cshtml @@ -59,6 +59,9 @@

Pneumatic

@{Html.RenderPartial("Pneumatic", Model);} + +

Nzbget

+ @{Html.RenderPartial("Nzbget", Model);}