diff --git a/NzbDrone.Core.Test/Files/Queue.xml b/NzbDrone.Core.Test/Files/Queue.xml
index 33e7622ce..079b7205b 100644
--- a/NzbDrone.Core.Test/Files/Queue.xml
+++ b/NzbDrone.Core.Test/Files/Queue.xml
@@ -15,13 +15,35 @@
770.96
770.96 MB
- Ubuntu Test
+ 30 Rock - 1x05 - Title [SDTV]
Normal
None
770.96
0
SABnzbd_nzo_xyr5ak
+ 3
+ 770.96 MB
+
+
+ Queued
+ 0
+ unknown
+ 0:00:00
+ 11h
+
+
+
+
+ 770.96
+ 770.96 MB
+ The Office (US) - 1x05 - Title [WEBDL]
+ Normal
+ None
+ 770.96
+ 0
+ SABnzbd_nzo_kqr9gl
+
3
770.96 MB
diff --git a/NzbDrone.Core.Test/ProviderTests/SabProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SabProviderTest.cs
index d696787d9..fc2f21b5a 100644
--- a/NzbDrone.Core.Test/ProviderTests/SabProviderTest.cs
+++ b/NzbDrone.Core.Test/ProviderTests/SabProviderTest.cs
@@ -23,6 +23,28 @@ namespace NzbDrone.Core.Test.ProviderTests
// ReSharper disable InconsistentNaming
public class SabProviderTest : CoreTest
{
+ private void WithSabConfigValues()
+ {
+ //Setup
+ string sabHost = "192.168.5.55";
+ int sabPort = 2222;
+ string apikey = "5c770e3197e4fe763423ee7c392c25d1";
+ string username = "admin";
+ string password = "pass";
+
+ var fakeConfig = Mocker.GetMock();
+ 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);
+ }
+
[Test]
public void AddByUrlSuccess()
{
@@ -168,8 +190,6 @@ public void IsInQueue_True()
string username = "admin";
string password = "pass";
-
-
var fakeConfig = Mocker.GetMock();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
@@ -187,7 +207,7 @@ public void IsInQueue_True()
.Returns(File.ReadAllText(@".\Files\Queue.xml"));
//Act
- bool result = Mocker.Resolve().IsInQueue("Ubuntu Test");
+ bool result = Mocker.Resolve().IsInQueue("30 Rock - 1x05 - Title [SDTV]");
//Assert
result.Should().BeTrue();
@@ -445,5 +465,54 @@ public void Get_Categories_Success_Config_Values()
result.Should().NotBeNull();
result.categories.Should().HaveCount(c => c > 0);
}
+
+ [Test]
+ public void GetQueue_should_return_an_empty_list_when_the_queue_is_empty()
+ {
+ WithSabConfigValues();
+
+ Mocker.GetMock()
+ .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
+ var result = Mocker.Resolve().GetQueue();
+
+ //Assert
+ result.Should().BeEmpty();
+ }
+
+ [Test]
+ [ExpectedException(typeof(ApplicationException), ExpectedMessage = "API Key Incorrect")]
+ public void GetQueue_should_return_an_empty_list_when_there_is_an_error_getting_the_queue()
+ {
+ WithSabConfigValues();
+
+ Mocker.GetMock()
+ .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
+ var result = Mocker.Resolve().GetQueue();
+
+ //Assert
+ result.Should().BeEmpty();
+ }
+
+ [Test]
+ public void GetQueue_should_return_a_list_with_items_when_the_queue_has_items()
+ {
+ WithSabConfigValues();
+
+ Mocker.GetMock()
+ .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
+ var result = Mocker.Resolve().GetQueue();
+
+ //Assert
+ result.Should().HaveCount(2);
+ }
}
}
\ No newline at end of file
diff --git a/NzbDrone.Core/Model/SabQueueItem.cs b/NzbDrone.Core/Model/SabQueueItem.cs
new file mode 100644
index 000000000..38fe0e8ae
--- /dev/null
+++ b/NzbDrone.Core/Model/SabQueueItem.cs
@@ -0,0 +1,13 @@
+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; }
+ }
+}
diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj
index d3b987d6f..4ab09745e 100644
--- a/NzbDrone.Core/NzbDrone.Core.csproj
+++ b/NzbDrone.Core/NzbDrone.Core.csproj
@@ -234,6 +234,7 @@
+
diff --git a/NzbDrone.Core/Providers/SabProvider.cs b/NzbDrone.Core/Providers/SabProvider.cs
index d38c3aedb..c3fedc277 100644
--- a/NzbDrone.Core/Providers/SabProvider.cs
+++ b/NzbDrone.Core/Providers/SabProvider.cs
@@ -10,6 +10,7 @@
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
+using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Core.Providers
{
@@ -103,6 +104,34 @@ public virtual bool IsInQueue(string title)
return false; //Not in Queue
}
+ public virtual List GetQueue()
+ {
+ const string action = "mode=queue&output=xml";
+ string request = GetSabRequest(action);
+ string response = _httpProvider.DownloadString(request);
+
+ XDocument xDoc = XDocument.Parse(response);
+
+ //If an Error Occurred, return)
+ if (xDoc.Descendants("error").Count() != 0)
+ throw new ApplicationException(xDoc.Descendants("error").FirstOrDefault().Value);
+
+ if (!xDoc.Descendants("queue").Any())
+ {
+ Logger.Debug("SAB Queue is empty.");
+ return new List();
+ }
+
+ var items = xDoc.Descendants("slot")
+ .Select(s => new SabQueueItem
+ {
+ Title = s.Element("filename").Value,
+ Id = s.Element("nzo_id").Value
+ });
+
+ return items.ToList();
+ }
+
public virtual String GetSabTitle(EpisodeParseResult parseResult)
{
//Handle Full Naming