SABnzbd settings will now dynamically get the categories available from SABnzbd when the category drop-box gets focus, it will use values on the page so there is no need to save your settings first.

pull/6/head
Mark McDowall 13 years ago
parent d554e9ec83
commit 1d983801e8

@ -0,0 +1 @@
{"categories":["*","anime","apps","books","consoles","ds-games","emulation","games","misc","movies","music","pda","resources","test","tv","tv-dvd","unknown","wii-games","xbox-dlc","xbox-xbla","xxx"]}

@ -147,6 +147,9 @@
<Content Include="Files\RSS\newbin_none_english.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\Categories_json.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Framework\AutoMoq\License.txt" />
<Content Include="Files\Feed.nzbmatrix.com.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

@ -292,7 +292,6 @@ namespace NzbDrone.Core.Test
Assert.AreEqual(excpected, actual);
}
[Test]
[Explicit]
public void AddNewzbingByUrlSuccess()
@ -335,5 +334,67 @@ namespace NzbDrone.Core.Test
//Assert
result.Should().BeTrue();
}
[Test]
public void Get_Categories_Success_Passed_Values()
{
//Setup
const string host = "192.168.5.55";
const int port = 2222;
const string apikey = "5c770e3197e4fe763423ee7c392c25d1";
const string username = "admin";
const string password = "pass";
var mocker = new AutoMoqer();
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=get_cats&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Categories_json.txt"));
//Act
var result = mocker.Resolve<SabProvider>().GetCategories(host, port, apikey, username, password);
//Assert
result.Should().NotBeNull();
result.categories.Should().HaveCount(c => c > 0);
result.categories.Should().NotContain("*");
}
[Test]
public void Get_Categories_Success_Config_Values()
{
//Setup
const string host = "192.168.5.55";
const int port = 2222;
const string apikey = "5c770e3197e4fe763423ee7c392c25d1";
const string username = "admin";
const string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(host);
fakeConfig.SetupGet(c => c.SabPort)
.Returns(port);
fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username);
fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password);
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=get_cats&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Categories_json.txt"));
//Act
var result = mocker.Resolve<SabProvider>().GetCategories();
//Assert
result.Should().NotBeNull();
result.categories.Should().HaveCount(c => c > 0);
result.categories.Should().NotContain("*");
}
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Model
{
public class SabnzbdCategoryModel
{
public List<string> categories { get; set; }
}
}

@ -191,6 +191,7 @@
<Compile Include="Model\JobQueueItem.cs" />
<Compile Include="Model\LanguageType.cs" />
<Compile Include="Model\Quality.cs" />
<Compile Include="Model\SabnzbdCategoryModel.cs" />
<Compile Include="Model\SabnzbdInfoModel.cs" />
<Compile Include="Model\Xbmc\ActionType.cs" />
<Compile Include="Model\Xbmc\ActivePlayersResult.cs" />

@ -157,7 +157,7 @@ namespace NzbDrone.Core.Providers.Core
public virtual String SabTvCategory
{
get { return GetValue("SabTvCategory", "TV"); }
get { return GetValue("SabTvCategory", "tv"); }
set { SetValue("SabTvCategory", value); }
}

@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Script.Serialization;
using System.Xml.Linq;
using Ninject;
using NLog;
@ -102,17 +103,6 @@ namespace NzbDrone.Core.Providers
return false; //Not in Queue
}
private string GetSabRequest(string action)
{
return string.Format(@"http://{0}:{1}/api?{2}&apikey={3}&ma_username={4}&ma_password={5}",
_configProvider.SabHost,
_configProvider.SabPort,
action,
_configProvider.SabApiKey,
_configProvider.SabUsername,
_configProvider.SabPassword);
}
public virtual String GetSabTitle(EpisodeParseResult parseResult)
{
//Show Name - 1x01-1x02 - Episode Name
@ -135,5 +125,51 @@ namespace NzbDrone.Core.Providers
return result;
}
public virtual SabnzbdCategoryModel GetCategories(string host = null, int port = 0, string apiKey = null, string username = null, string password = null)
{
//Get saved values if any of these are defaults
if (host == null)
host = _configProvider.SabHost;
if (port == 0)
port = _configProvider.SabPort;
if (apiKey == null)
apiKey = _configProvider.SabApiKey;
if (username == null)
username = _configProvider.SabUsername;
if (password == null)
password = _configProvider.SabPassword;
const string action = "mode=get_cats&output=json";
var command = string.Format(@"http://{0}:{1}/api?{2}&apikey={3}&ma_username={4}&ma_password={5}",
host, port, action, apiKey, username, password);
var response = _httpProvider.DownloadString(command);
if (String.IsNullOrWhiteSpace(response))
return new SabnzbdCategoryModel{categories = new List<string>()};
var deserialized = new JavaScriptSerializer().Deserialize<SabnzbdCategoryModel>(response);
deserialized.categories.Remove("*");
return deserialized;
}
private string GetSabRequest(string action)
{
return string.Format(@"http://{0}:{1}/api?{2}&apikey={3}&ma_username={4}&ma_password={5}",
_configProvider.SabHost,
_configProvider.SabPort,
action,
_configProvider.SabApiKey,
_configProvider.SabUsername,
_configProvider.SabPassword);
}
}
}

@ -3,17 +3,22 @@ using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Web.Models;
namespace NzbDrone.Web.Controllers
{
public class CommandController : Controller
{
private readonly JobProvider _jobProvider;
private readonly SabProvider _sabProvider;
public CommandController(JobProvider jobProvider)
public CommandController(JobProvider jobProvider, SabProvider sabProvider)
{
_jobProvider = jobProvider;
_sabProvider = sabProvider;
}
public JsonResult RssSync()
@ -37,5 +42,20 @@ namespace NzbDrone.Web.Controllers
return new JsonResult { Data = "ok", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
[HttpPost]
public JsonResult GetSabnzbdCategories(string host, int port, string apiKey, string username, string password)
{
try
{
return new JsonResult {Data = _sabProvider.GetCategories(host, port, apiKey, username, password)};
}
catch (Exception ex)
{
//Todo: Log the error
throw;
}
}
}
}

@ -80,8 +80,8 @@ namespace NzbDrone.Web.Controllers
public ActionResult Sabnzbd()
{
var sabDropDir = _configProvider.SabDropDirectory;
var selectList = new SelectList(new List<string> { sabDropDir }, sabDropDir);
var tvCategory = _configProvider.SabTvCategory;
var tvCategorySelectList = new SelectList(new[] { tvCategory });
var model = new SabnzbdSettingsModel
{
@ -92,8 +92,8 @@ namespace NzbDrone.Web.Controllers
SabPassword = _configProvider.SabPassword,
SabTvCategory = _configProvider.SabTvCategory,
SabTvPriority = _configProvider.SabTvPriority,
SabDropDirectory = sabDropDir,
SabDropDirectorySelectList = selectList
SabDropDirectory = _configProvider.SabDropDirectory,
SabTvCategorySelectList = tvCategorySelectList
};
return View(model);

@ -57,6 +57,6 @@ namespace NzbDrone.Web.Models
[DisplayFormat(ConvertEmptyStringToNull = false)]
public string SabDropDirectory { get; set; }
public SelectList SabDropDirectorySelectList { get; set; }
public SelectList SabTvCategorySelectList { get; set; }
}
}

@ -54,7 +54,7 @@
<label class="labelClass">@Html.LabelFor(m => m.SabTvCategory)
<span class="small">@Html.DescriptionFor(m => m.SabTvCategory)</span>
</label>
@Html.TextBoxFor(m => m.SabTvCategory, new { @class = "inputClass" })
@Html.DropDownListFor(m => m.SabTvCategory, Model.SabTvCategorySelectList, new { @class = "inputClass selectClass" })
<label class="labelClass">@Html.LabelFor(m => m.SabTvPriority)
<span class="small">@Html.DescriptionFor(m => m.SabTvPriority)</span>
@ -96,5 +96,44 @@
$('#SabApiKey').val(data.ApiKey);
}
}
var sabCategoryUrl = '../Command/GetSabnzbdCategories';
$('#SabTvCategory').focus(function () {
var host = $('#SabHost').val();
var port = $('#SabPort').val();
var apiKey = $('#SabApiKey').val();
var username = $('#SabUsername').val();
var password = $('#SabPassword').val();
$.ajax({
type: "POST",
url: sabCategoryUrl,
data: jQuery.param({ host: host, port: port, apiKey: apiKey, username: username, password: password }),
error: function (req, status, error) {
$.each($('#SabTvCategory option'), function () {
$(this).remove();
});
$('#SabTvCategory').append($('<option />').val('tv').text('Please check your SABnzbd Settings'));
},
success: function (data, textStatus, jqXHR) {
//Get the current value
var currentlySelected = $('#SabTvCategory').val();
//Remove all existing options
$.each($('#SabTvCategory option'), function () {
$(this).remove();
});
//Add the new ones
$.each(data.categories, function () {
$('#SabTvCategory').append($('<option />').val(this.toString()).text(this.toString()));
});
//Attempt to reset to the preiously selected value (change to lower-case)
$("#SabTvCategory").val(currentlySelected.toLowerCase());
}
});
});
</script>
}

@ -1,9 +1,38 @@
<img src='../../Content/Images/ignoredNeutral.png' class='ignoredEpisodesMaster ignoreEpisode' id='master' value='10'/>
@Html.DropDownList("SabTvCategory", new SelectList(new List<string> { "TV" }))
<script>
$(".ignoreEpisode").live("click", function () {
var toggle = $(this);
var value = $(this).attr('value');
var test = 0;
var sabCategoryUrl = '../Command/GetSabnzbdCategories';
$('#SabTvCategory').focus(function () {
$.ajax({
type: "POST",
url: sabCategoryUrl,
data: jQuery.param({ host: '192.168.5.55', port: 2222, apiKey: '5c770e3197e4fe763423ee7c392c25d1', username: 'admin', password: 'pass' }),
error: function (req, status, error) {
$.each($('#SabTvCategory option'), function () {
$(this).remove();
});
$('#SabTvCategory').append($('<option />').val('tv').text('Please check your SABnzbd Settings'));
},
success: function (data, textStatus, jqXHR) {
//Get the current value
var currentlySelected = $('#SabTvCategory').val();
//Remove all existing options
$.each($('#SabTvCategory option'), function () {
$(this).remove();
});
//Add the new ones
$.each(data.categories, function () {
$('#SabTvCategory').append($('<option />').val(this.toString()).text(this.toString()));
});
//Attempt to reset to the preiously selected value (change to lower-case)
$("#SabTvCategory").val(currentlySelected.toLowerCase());
}
});
});
</script>
Loading…
Cancel
Save