SabProvider now gets JSON instead of XML for history and queue.

pull/4/head
Mark McDowall 13 years ago
parent 26c4240a6b
commit b4eed1a657

@ -0,0 +1,72 @@
{
"total_size": "40.30 GB",
"month_size": "20.23 GB",
"week_size": "5.12 GB",
"cache_limit":"-1",
"paused":true,
"new_rel_url":"",
"restart_req":false,
"slots":[
{
"action_line":"",
"show_details":"True",
"script_log":"",
"meta":null,
"fail_message":"",
"loaded":false,
"id":605,
"size":"778.1 MB",
"category":"Apps",
"pp":"D",
"completeness":0,
"script":"",
"nzb_name":"Ubuntu.nzb",
"download_time":567,
"storage":"X:\\Apps\\Ubuntu",
"status":"Completed",
"script_line":"",
"completed":1236646078,
"nzo_id":"SABnzbd_nzo_ipet0h",
"downloaded":815878352,
"report":"000000",
"path":"Ubuntu",
"postproc_time":368,
"name":"Ubuntu",
"url":"https://newzbin.com/browse/post/000000/",
"bytes":815878352,
"url_info":"http://google.com",
"stage_log":[
{"name":"download","actions":["Downloaded in 9 minutes 27 seconds at an average of 1404kB/s"]},
{"name":"repair","actions":["[ubuntu] Repaired in 4 minutes 24 seconds","[ubuntu.sample] Quick Check OK"]},
{"name":"unpack","actions":["[ubuntu] Unpacked 1 file/folder in 36 seconds"]}
]
}],
"helpuri":"http://wiki.sabnzbd.org/",
"uptime":"12m",
"version":"trunk",
"diskspacetotal2":"503.32",
"color_scheme":"",
"darwin":false,
"nt":true,
"status":"Paused",
"last_warning":"",
"have_warnings":"0",
"cache_art":"0",
"finishaction":null,
"noofslots":516,
"cache_size":"0",
"new_release":"",
"pause_int":"0",
"mbleft":"785.89",
"diskspace2":"25.08",
"diskspace1":"25.08",
"diskspacetotal1":"503.32",
"timeleft":"0:00:00",
"mb":"785.89",
"eta":"unknown",
"nzb_quota":"",
"loadavg":"",
"kbpersec":"0.00",
"speedlimit":"0",
"webdir":"path\\to\\templates"
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,38 @@
{
"total_size": "40.30 GB",
"month_size": "20.23 GB",
"week_size": "5.12 GB",
"cache_limit":"-1",
"paused":true,
"new_rel_url":"",
"restart_req":false,
"slots":[ ],
"helpuri":"http://wiki.sabnzbd.org/",
"uptime":"12m",
"version":"trunk",
"diskspacetotal2":"503.32",
"color_scheme":"",
"darwin":false,
"nt":true,
"status":"Paused",
"last_warning":"",
"have_warnings":"0",
"cache_art":"0",
"finishaction":null,
"noofslots":516,
"cache_size":"0",
"new_release":"",
"pause_int":"0",
"mbleft":"785.89",
"diskspace2":"25.08",
"diskspace1":"25.08",
"diskspacetotal1":"503.32",
"timeleft":"0:00:00",
"mb":"785.89",
"eta":"unknown",
"nzb_quota":"",
"loadavg":"",
"kbpersec":"0.00",
"speedlimit":"0",
"webdir":"path\\to\\templates"
}

@ -0,0 +1,4 @@
{
"status": false,
"error": "API Key Incorrect"
}

@ -0,0 +1,97 @@
{
"cache_limit":"-1",
"categories":[
"None",
"apps",
"books",
"consoles",
"emulation",
"games",
"misc",
"movies",
"music",
"pda",
"resources",
"tv"
],
"scripts":[
"None"
],
"paused":true,
"new_rel_url":"",
"restart_req":false,
"slots":[
{
"status":"Queued",
"index":0,
"eta":"unknown",
"timeleft":"0:00:00",
"avg_age":"43d",
"script":"None",
"msgid":"4295398",
"verbosity":"",
"mb":"785.89",
"filename":"30 Rock - 1x05 - Title [SDTV]",
"priority":"High",
"cat":"Apps",
"mbleft":"785.89",
"percentage":"0",
"nzo_id":"SABnzbd_nzo_wgmb1m",
"unpackopts":"3",
"size":"785.9 MB"
},
{
"status":"Queued",
"index":0,
"eta":"unknown",
"timeleft":"0:00:00",
"avg_age":"43d",
"script":"None",
"msgid":"4295398",
"verbosity":"",
"mb":"785.89",
"filename":"The Office (US) - 1x05 - Title [WEBDL]",
"priority":"High",
"cat":"Apps",
"mbleft":"785.89",
"percentage":"0",
"nzo_id":"SABnzbd_nzo_wgmb1m",
"unpackopts":"3",
"size":"785.9 MB"
}],
"helpuri":"http://wiki.sabnzbd.org/",
"uptime":"6m",
"refresh_rate":"",
"isverbose":false,
"start":0,
"version":"trunk",
"diskspacetotal2":"503.32",
"color_scheme":"",
"darwin":false,
"nt":true,
"status":"Paused",
"last_warning":"",
"have_warnings":"0",
"cache_art":"0",
"finishaction":null,
"noofslots":1,
"cache_size":"0",
"finish":0,
"new_release":"",
"pause_int":"0"
,"mbleft":"785.89",
"diskspace2":"25.08",
"diskspace1":"25.08",
"diskspacetotal1":"503.32",
"timeleft":"0:00:00",
"mb":"785.89",
"newzbinDetails":true,
"eta":"unknown",
"nzb_quota":"",
"loadavg":"",
"limit":0,
"kbpersec":"0.00",
"speedlimit":"0",
"webdir":"path\\to\\templates",
"queue_details":"0"
}

@ -1,142 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<queue>
<active_lang>us-en</active_lang>
<session>5c770e3197e4fe763423ee7c392c25d1</session>
<slots>
<slot>
<status>Queued</status>
<index>0</index>
<eta>unknown</eta>
<timeleft>0:00:00</timeleft>
<avg_age>11h</avg_age>
<script>None</script>
<msgid></msgid>
<verbosity></verbosity>
<mb>770.96</mb>
<sizeleft>770.96 MB</sizeleft>
<filename>30 Rock - 1x05 - Title [SDTV]</filename>
<priority>Normal</priority>
<cat>None</cat>
<mbleft>770.96</mbleft>
<percentage>0</percentage>
<nzo_id>SABnzbd_nzo_xyr5ak</nzo_id>
<unpackopts>3</unpackopts>
<size>770.96 MB</size>
</slot>
<slot>
<status>Queued</status>
<index>0</index>
<eta>unknown</eta>
<timeleft>0:00:00</timeleft>
<avg_age>11h</avg_age>
<script>None</script>
<msgid></msgid>
<verbosity></verbosity>
<mb>770.96</mb>
<sizeleft>770.96 MB</sizeleft>
<filename>The Office (US) - 1x05 - Title [WEBDL]</filename>
<priority>Normal</priority>
<cat>None</cat>
<mbleft>770.96</mbleft>
<percentage>0</percentage>
<nzo_id>SABnzbd_nzo_kqr9gl</nzo_id>
<unpackopts>3</unpackopts>
<size>770.96 MB</size>
</slot>
</slots>
<speed>0 </speed>
<size>770.96 MB</size>
<limit>0</limit>
<start>0</start>
<diskspacetotal2>259.45</diskspacetotal2>
<darwin>False</darwin>
<last_warning></last_warning>
<have_warnings>0</have_warnings>
<noofslots>1</noofslots>
<pause_int>0</pause_int>
<categories>
<category>None</category>
<category>anime</category>
<category>apps</category>
<category>books</category>
<category>consoles</category>
<category>ds-games</category>
<category>emulation</category>
<category>games</category>
<category>misc</category>
<category>movies</category>
<category>music</category>
<category>pda</category>
<category>resources</category>
<category>test</category>
<category>tv</category>
<category>tv-dvd</category>
<category>unknown</category>
<category>wii-games</category>
<category>xbox-dlc</category>
<category>xbox-xbla</category>
</categories>
<diskspacetotal1>259.45</diskspacetotal1>
<mb>770.96</mb>
<loadavg></loadavg>
<cache_max>157286400</cache_max>
<speedlimit></speedlimit>
<webdir>C:\Program Files\SABnzbd\interfaces\Plush\templates</webdir>
<paused>True</paused>
<isverbose>False</isverbose>
<restart_req>False</restart_req>
<power_options>True</power_options>
<helpuri>http://wiki.sabnzbd.org/</helpuri>
<uptime>4d</uptime>
<refresh_rate></refresh_rate>
<version>0.6.x</version>
<color_scheme></color_scheme>
<new_release></new_release>
<nt>True</nt>
<status>Paused</status>
<finish>0</finish>
<cache_art>0</cache_art>
<paused_all>False</paused_all>
<finishaction></finishaction>
<sizeleft>770.96 MB</sizeleft>
<cache_size>0B</cache_size>
<mbleft>770.96</mbleft>
<diskspace2>1177.64</diskspace2>
<diskspace1>1177.64</diskspace1>
<scripts>
<script>None</script>
<script>Alias.config</script>
<script>ConsoleCategories.config</script>
<script>exiso.exe</script>
<script>Movies.exe</script>
<script>Movies.exe.config</script>
<script>Movies.pdb</script>
<script>PreQueue.exe</script>
<script>PreQueue.exe.config</script>
<script>PreQueue.pdb</script>
<script>SABTest.exe</script>
<script>TVMove.exe</script>
<script>TVMove.exe.config</script>
<script>TVMove_0.4.1.exe</script>
<script>XBox360.exe</script>
<script>XBox360.exe.config</script>
</scripts>
<timeleft>0:00:00</timeleft>
<nzb_quota></nzb_quota>
<eta>unknown</eta>
<kbpersec>0.00</kbpersec>
<new_rel_url></new_rel_url>
<queue_details>0</queue_details>
</queue>

@ -0,0 +1,59 @@
{
"cache_limit":"-1",
"categories":[
"None",
"apps",
"books",
"consoles",
"emulation",
"games",
"misc",
"movies",
"music",
"pda",
"resources",
"tv"
],
"scripts":[
"None"
],
"paused":true,
"new_rel_url":"",
"restart_req":false,
"slots":[ ],
"helpuri":"http://wiki.sabnzbd.org/",
"uptime":"6m",
"refresh_rate":"",
"isverbose":false,
"start":0,
"version":"trunk",
"diskspacetotal2":"503.32",
"color_scheme":"",
"darwin":false,
"nt":true,
"status":"Paused",
"last_warning":"",
"have_warnings":"0",
"cache_art":"0",
"finishaction":null,
"noofslots":1,
"cache_size":"0",
"finish":0,
"new_release":"",
"pause_int":"0"
,"mbleft":"785.89",
"diskspace2":"25.08",
"diskspace1":"25.08",
"diskspacetotal1":"503.32",
"timeleft":"0:00:00",
"mb":"785.89",
"newzbinDetails":true,
"eta":"unknown",
"nzb_quota":"",
"loadavg":"",
"limit":0,
"kbpersec":"0.00",
"speedlimit":"0",
"webdir":"path\\to\\templates",
"queue_details":"0"
}

@ -1,94 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<queue><active_lang>us-en</active_lang>
<session>5c770e3197e4fe763423ee7c392c25d1</session>
<slots></slots>
<speed>0 </speed>
<size>0B</size>
<limit>0</limit>
<start>0</start>
<diskspacetotal2>259.45</diskspacetotal2>
<darwin>False</darwin>
<last_warning></last_warning>
<have_warnings>0</have_warnings>
<noofslots>0</noofslots>
<pause_int>0</pause_int>
<categories><category>None</category>
<category>anime</category>
<category>apps</category>
<category>books</category>
<category>consoles</category>
<category>ds-games</category>
<category>emulation</category>
<category>games</category>
<category>misc</category>
<category>movies</category>
<category>music</category>
<category>pda</category>
<category>resources</category>
<category>test</category>
<category>tv</category>
<category>tv-dvd</category>
<category>unknown</category>
<category>wii-games</category>
<category>xbox-dlc</category>
<category>xbox-xbla</category>
</categories>
<diskspacetotal1>259.45</diskspacetotal1>
<mb>0.00</mb>
<loadavg></loadavg>
<cache_max>157286400</cache_max>
<speedlimit></speedlimit>
<webdir>C:\Program Files\SABnzbd\interfaces\Plush\templates</webdir>
<paused>False</paused>
<isverbose>False</isverbose>
<restart_req>False</restart_req>
<power_options>True</power_options>
<helpuri>http://wiki.sabnzbd.org/</helpuri>
<uptime>4d</uptime>
<refresh_rate></refresh_rate>
<version>0.6.x</version>
<color_scheme></color_scheme>
<new_release></new_release>
<nt>True</nt>
<status>Idle</status>
<finish>0</finish>
<cache_art>0</cache_art>
<paused_all>False</paused_all>
<finishaction></finishaction>
<sizeleft>0B</sizeleft>
<cache_size>0B</cache_size>
<mbleft>0.00</mbleft>
<diskspace2>1177.64</diskspace2>
<diskspace1>1177.64</diskspace1>
<scripts><script>None</script>
<script>Alias.config</script>
<script>ConsoleCategories.config</script>
<script>exiso.exe</script>
<script>Movies.exe</script>
<script>Movies.exe.config</script>
<script>Movies.pdb</script>
<script>PreQueue.exe</script>
<script>PreQueue.exe.config</script>
<script>PreQueue.pdb</script>
<script>SABTest.exe</script>
<script>TVMove.exe</script>
<script>TVMove.exe.config</script>
<script>TVMove_0.4.1.exe</script>
<script>XBox360.exe</script>
<script>XBox360.exe.config</script>
</scripts>
<timeleft>0:00:00</timeleft>
<nzb_quota></nzb_quota>
<eta>unknown</eta>
<kbpersec>0.00</kbpersec>
<new_rel_url></new_rel_url>
<queue_details>0</queue_details>
</queue>

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<result><status>False</status>
<error>API Key Incorrect</error>
</result>

@ -183,7 +183,18 @@
<Content Include="App_Data\Config.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\History.xml" />
<Content Include="Files\HistoryEmpty.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\Queue.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\History.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\JsonError.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\RSS\newbin_none_english.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
@ -217,14 +228,7 @@
<Content Include="Files\RSS\nzbsorg.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\Queue.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<Content Include="Files\QueueEmpty.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\QueueError.xml">
<Content Include="Files\QueueEmpty.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

@ -9,6 +9,7 @@ using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Sabnzbd;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
@ -54,7 +55,7 @@ namespace NzbDrone.Core.Test.ProviderTests
const string apikey = "5c770e3197e4fe763423ee7c392c25d1";
const string username = "admin";
const string password = "pass";
const SabnzbdPriorityType priority = SabnzbdPriorityType.Normal;
const SabPriorityType priority = SabPriorityType.Normal;
const string category = "tv";
@ -101,7 +102,7 @@ namespace NzbDrone.Core.Test.ProviderTests
const string apikey = "5c770e3197e4fe763423ee7c392c25d1";
const string username = "admin";
const string password = "pass";
const SabnzbdPriorityType priority = SabnzbdPriorityType.Normal;
const SabPriorityType priority = SabPriorityType.Normal;
const string category = "tv";
@ -147,7 +148,7 @@ namespace NzbDrone.Core.Test.ProviderTests
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
var priority = SabnzbdPriorityType.Normal;
var priority = SabPriorityType.Normal;
string category = "tv";
@ -180,108 +181,6 @@ namespace NzbDrone.Core.Test.ProviderTests
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void IsInQueue_True()
{
//Setup
string sabHost = "192.168.5.55";
int sabPort = 2222;
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
.Returns(sabPort);
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=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Queue.xml"));
//Act
bool result = Mocker.Resolve<SabProvider>().IsInQueue("30 Rock - 1x05 - Title [SDTV]");
//Assert
result.Should().BeTrue();
}
[Test]
public void IsInQueue_False_Empty()
{
//Setup
string sabHost = "192.168.5.55";
int sabPort = 2222;
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
.Returns(sabPort);
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=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueEmpty.xml"));
//Act
bool result = Mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
//Assert
Assert.IsFalse(result);
}
[Test]
[ExpectedException(typeof(ApplicationException), ExpectedMessage = "API Key Incorrect")]
public void IsInQueue_False_Error()
{
//Setup
string sabHost = "192.168.5.55";
int sabPort = 2222;
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
.Returns(sabPort);
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=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueError.xml"));
//Act
Mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
}
[Test]
[TestCase(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, false, "My Series Name - 1x2 - My Episode Title [DVD]")]
[TestCase(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, true, "My Series Name - 1x2 - My Episode Title [DVD] [Proper]")]
@ -373,7 +272,7 @@ namespace NzbDrone.Core.Test.ProviderTests
const string apikey = "f37dc33baec2e5566f5aec666287870d";
const string username = "root";
const string password = "*************";
const SabnzbdPriorityType priority = SabnzbdPriorityType.Normal;
const SabPriorityType priority = SabPriorityType.Normal;
const string category = "tv";
@ -472,8 +371,8 @@ namespace NzbDrone.Core.Test.ProviderTests
WithSabConfigValues();
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueEmpty.xml"));
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueEmpty.txt"));
//Act
var result = Mocker.Resolve<SabProvider>().GetQueue();
@ -489,8 +388,8 @@ namespace NzbDrone.Core.Test.ProviderTests
WithSabConfigValues();
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueError.xml"));
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\JsonError.txt"));
//Act
var result = Mocker.Resolve<SabProvider>().GetQueue();
@ -505,8 +404,8 @@ namespace NzbDrone.Core.Test.ProviderTests
WithSabConfigValues();
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Queue.xml"));
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Queue.txt"));
//Act
var result = Mocker.Resolve<SabProvider>().GetQueue();
@ -514,5 +413,54 @@ namespace NzbDrone.Core.Test.ProviderTests
//Assert
result.Should().HaveCount(2);
}
[Test]
public void GetHistory_should_return_a_list_with_items_when_the_history_has_items()
{
WithSabConfigValues();
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=history&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\History.txt"));
//Act
var result = Mocker.Resolve<SabProvider>().GetHistory();
//Assert
result.Should().HaveCount(1);
}
[Test]
public void GetHistory_should_return_an_empty_list_when_the_queue_is_empty()
{
WithSabConfigValues();
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=history&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\HistoryEmpty.txt"));
//Act
var result = Mocker.Resolve<SabProvider>().GetHistory();
//Assert
result.Should().BeEmpty();
}
[Test]
[ExpectedException(typeof(ApplicationException), ExpectedMessage = "API Key Incorrect")]
public void GetHistory_should_return_an_empty_list_when_there_is_an_error_getting_the_queue()
{
WithSabConfigValues();
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=history&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\JsonError.txt"));
//Act
var result = Mocker.Resolve<SabProvider>().GetHistory();
//Assert
result.Should().BeEmpty();
}
}
}

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Model
{
public class SabQueueItem
{
public string Id { get; set; }
public string Title { get; set; }
}
}

@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace NzbDrone.Core.Model
namespace NzbDrone.Core.Model.Sabnzbd
{
public class SabnzbdCategoryModel
public class SabCategoryModel
{
public List<string> categories { get; set; }
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace NzbDrone.Core.Model.Sabnzbd
{
public class SabHistory
{
public bool Paused { get; set; }
[JsonProperty(PropertyName = "slots")]
public List<SabHistoryItem> Items { get; set; }
}
}

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace NzbDrone.Core.Model.Sabnzbd
{
public class SabHistoryItem
{
[JsonProperty(PropertyName = "fail_message")]
public string FailMessage { get; set; }
public string Size { get; set; }
public string Category { get; set; }
[JsonProperty(PropertyName = "nzb_name")]
public string NzbName { get; set; }
[JsonProperty(PropertyName = "download_time")]
public int DownloadTime { get; set; }
public string Storage { get; set; }
public string Status { get; set; }
[JsonProperty(PropertyName = "nzo_id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "name")]
public string Title { get; set; }
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace NzbDrone.Core.Model.Sabnzbd
{
public class SabJsonError
{
public string Status { get; set; }
public string Error { get; set; }
}
}

@ -1,6 +1,6 @@
namespace NzbDrone.Core.Model
namespace NzbDrone.Core.Model.Sabnzbd
{
public class SabnzbdInfoModel
public class SabModel
{
public string Host { get; set; }
public int Port { get; set; }

@ -1,6 +1,6 @@
namespace NzbDrone.Core.Model
namespace NzbDrone.Core.Model.Sabnzbd
{
public enum SabnzbdPriorityType
public enum SabPriorityType
{
Default = -100,
Paused = -2,

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace NzbDrone.Core.Model.Sabnzbd
{
public class SabQueue
{
public bool Paused { get; set; }
[JsonProperty(PropertyName = "slots")]
public List<SabQueueItem> Items { get; set; }
}
}

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace NzbDrone.Core.Model.Sabnzbd
{
public class SabQueueItem
{
public string Status { get; set; }
public int Index { get; set; }
public TimeSpan Timeleft { get; set; }
[JsonProperty(PropertyName = "mb")]
public decimal Size { get; set; }
[JsonProperty(PropertyName = "filename")]
public string Title { get; set; }
public SabPriorityType Priority { get; set; }
[JsonProperty(PropertyName = "cat")]
public string Category { get; set; }
[JsonProperty(PropertyName = "mbleft")]
public decimal SizeLeft { get; set; }
public int Percentage { get; set; }
[JsonProperty(PropertyName = "nzo_id")]
public string Id { get; set; }
}
}

@ -232,9 +232,13 @@
<Compile Include="Model\LanguageType.cs" />
<Compile Include="Model\MisnamedEpisodeModel.cs" />
<Compile Include="Model\Quality.cs" />
<Compile Include="Model\SabnzbdCategoryModel.cs" />
<Compile Include="Model\SabnzbdInfoModel.cs" />
<Compile Include="Model\SabQueueItem.cs" />
<Compile Include="Model\Sabnzbd\SabHistoryItem.cs" />
<Compile Include="Model\Sabnzbd\SabHistory.cs" />
<Compile Include="Model\Sabnzbd\SabJsonError.cs" />
<Compile Include="Model\Sabnzbd\SabQueue.cs" />
<Compile Include="Model\Sabnzbd\SabCategoryModel.cs" />
<Compile Include="Model\Sabnzbd\SabModel.cs" />
<Compile Include="Model\Sabnzbd\SabQueueItem.cs" />
<Compile Include="Model\Twitter\TwitterAuthorizationModel.cs" />
<Compile Include="Model\UpdatePackage.cs" />
<Compile Include="Model\Xbmc\ActionType.cs" />
@ -306,7 +310,7 @@
<Compile Include="Model\EpisodeParseResult.cs" />
<Compile Include="Model\EpisodeSortingType.cs" />
<Compile Include="Model\EpisodeStatusType.cs" />
<Compile Include="Model\SabnzbdPriorityType.cs" />
<Compile Include="Model\Sabnzbd\SabPriorityType.cs" />
<Compile Include="Model\SeasonParseResult.cs" />
<Compile Include="Model\UpcomingEpisodesModel.cs" />
<Compile Include="Providers\Indexer\IndexerBase.cs" />

@ -7,6 +7,7 @@ using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Sabnzbd;
namespace NzbDrone.Core.Providers
{
@ -14,7 +15,7 @@ namespace NzbDrone.Core.Providers
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public SabnzbdInfoModel AutoConfigureSab()
public SabModel AutoConfigureSab()
{
var info = GetConnectionList();
return FindApiKey(info);
@ -41,13 +42,13 @@ namespace NzbDrone.Core.Providers
return info;
}
private SabnzbdInfoModel FindApiKey(List<ConnectionInfoModel> info)
private SabModel FindApiKey(List<ConnectionInfoModel> info)
{
foreach (var connection in info)
{
var apiKey = GetApiKey(connection.Address, connection.Port);
if (!String.IsNullOrEmpty(apiKey))
return new SabnzbdInfoModel
return new SabModel
{
Host = connection.Address,
Port = connection.Port,

@ -3,6 +3,7 @@ using System.Collections.Generic;
using Ninject;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Sabnzbd;
using NzbDrone.Core.Repository;
using PetaPoco;
@ -126,9 +127,9 @@ namespace NzbDrone.Core.Providers.Core
set { SetValue("SabTvCategory", value); }
}
public virtual SabnzbdPriorityType SabTvPriority
public virtual SabPriorityType SabTvPriority
{
get { return (SabnzbdPriorityType)GetValueInt("SabTvPriority"); }
get { return (SabPriorityType)GetValueInt("SabTvPriority"); }
set { SetValue("SabTvPriority", (int)value); }
}

@ -6,9 +6,11 @@ using System.Text.RegularExpressions;
using System.Web;
using System.Web.Script.Serialization;
using System.Xml.Linq;
using Newtonsoft.Json;
using Ninject;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Sabnzbd;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository.Quality;
@ -104,32 +106,26 @@ namespace NzbDrone.Core.Providers
return false; //Not in Queue
}
public virtual List<SabQueueItem> GetQueue()
public virtual List<SabQueueItem> GetQueue(int start = 0, int limit = 0)
{
const string action = "mode=queue&output=xml";
string action = String.Format("mode=queue&output=json&start={0}&limit={1}", start, limit);
string request = GetSabRequest(action);
string response = _httpProvider.DownloadString(request);
XDocument xDoc = XDocument.Parse(response);
CheckForError(response);
//If an Error Occurred, return)
if (xDoc.Descendants("error").Count() != 0)
throw new ApplicationException(xDoc.Descendants("error").FirstOrDefault().Value);
return JsonConvert.DeserializeObject<SabQueue>(response).Items;
}
if (!xDoc.Descendants("queue").Any())
{
Logger.Debug("SAB Queue is empty.");
return new List<SabQueueItem>();
}
public virtual List<SabHistoryItem> GetHistory(int start = 0, int limit = 0)
{
string action = String.Format("mode=history&output=json&start={0}&limit={1}", start, limit);
string request = GetSabRequest(action);
string response = _httpProvider.DownloadString(request);
var items = xDoc.Descendants("slot")
.Select(s => new SabQueueItem
{
Title = s.Element("filename").Value,
Id = s.Element("nzo_id").Value
});
CheckForError(response);
return items.ToList();
return JsonConvert.DeserializeObject<SabHistory>(response).Items;
}
public virtual String GetSabTitle(EpisodeParseResult parseResult)
@ -178,7 +174,7 @@ 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)
public virtual SabCategoryModel 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)
@ -204,9 +200,9 @@ namespace NzbDrone.Core.Providers
var response = _httpProvider.DownloadString(command);
if (String.IsNullOrWhiteSpace(response))
return new SabnzbdCategoryModel{categories = new List<string>()};
return new SabCategoryModel{categories = new List<string>()};
var deserialized = new JavaScriptSerializer().Deserialize<SabnzbdCategoryModel>(response);
var deserialized = JsonConvert.DeserializeObject<SabCategoryModel>(response);
return deserialized;
}
@ -221,5 +217,13 @@ namespace NzbDrone.Core.Providers
_configProvider.SabUsername,
_configProvider.SabPassword);
}
private void CheckForError(string response)
{
var result = JsonConvert.DeserializeObject<SabJsonError>(response);
if (result.Status.Equals("false", StringComparison.InvariantCultureIgnoreCase))
throw new ApplicationException(result.Error);
}
}
}

@ -3,6 +3,7 @@ using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Sabnzbd;
namespace NzbDrone.Web.Models
{
@ -50,7 +51,7 @@ namespace NzbDrone.Web.Models
[Required(ErrorMessage = "Please select a valid priority")]
[DisplayName("SABnzbd Priority")]
[Description("Priority to use when sending NZBs to SABnzbd")]
public SabnzbdPriorityType SabTvPriority { get; set; }
public SabPriorityType SabTvPriority { get; set; }
[DisplayName("SABnzbd TV Directory")]
[Description("The directory where SABnzbd downloads TV shows to (NzbDrone will sort them for you)")]

Loading…
Cancel
Save