mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-31 07:52:37 +01:00
SabProvider can now get the entire Queue for additional processing.
This commit is contained in:
parent
7acb563c05
commit
26c4240a6b
@ -15,13 +15,35 @@
|
|||||||
<verbosity></verbosity>
|
<verbosity></verbosity>
|
||||||
<mb>770.96</mb>
|
<mb>770.96</mb>
|
||||||
<sizeleft>770.96 MB</sizeleft>
|
<sizeleft>770.96 MB</sizeleft>
|
||||||
<filename>Ubuntu Test</filename>
|
<filename>30 Rock - 1x05 - Title [SDTV]</filename>
|
||||||
<priority>Normal</priority>
|
<priority>Normal</priority>
|
||||||
<cat>None</cat>
|
<cat>None</cat>
|
||||||
<mbleft>770.96</mbleft>
|
<mbleft>770.96</mbleft>
|
||||||
<percentage>0</percentage>
|
<percentage>0</percentage>
|
||||||
<nzo_id>SABnzbd_nzo_xyr5ak</nzo_id>
|
<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>
|
<unpackopts>3</unpackopts>
|
||||||
<size>770.96 MB</size>
|
<size>770.96 MB</size>
|
||||||
</slot>
|
</slot>
|
||||||
|
@ -23,6 +23,28 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class SabProviderTest : CoreTest
|
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<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);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void AddByUrlSuccess()
|
public void AddByUrlSuccess()
|
||||||
{
|
{
|
||||||
@ -168,8 +190,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||||||
string username = "admin";
|
string username = "admin";
|
||||||
string password = "pass";
|
string password = "pass";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var fakeConfig = Mocker.GetMock<ConfigProvider>();
|
var fakeConfig = Mocker.GetMock<ConfigProvider>();
|
||||||
fakeConfig.SetupGet(c => c.SabHost)
|
fakeConfig.SetupGet(c => c.SabHost)
|
||||||
.Returns(sabHost);
|
.Returns(sabHost);
|
||||||
@ -187,7 +207,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||||||
.Returns(File.ReadAllText(@".\Files\Queue.xml"));
|
.Returns(File.ReadAllText(@".\Files\Queue.xml"));
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
bool result = Mocker.Resolve<SabProvider>().IsInQueue("Ubuntu Test");
|
bool result = Mocker.Resolve<SabProvider>().IsInQueue("30 Rock - 1x05 - Title [SDTV]");
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
@ -445,5 +465,54 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result.categories.Should().HaveCount(c => c > 0);
|
result.categories.Should().HaveCount(c => c > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetQueue_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=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
|
||||||
|
.Returns(File.ReadAllText(@".\Files\QueueEmpty.xml"));
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = Mocker.Resolve<SabProvider>().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<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"));
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = Mocker.Resolve<SabProvider>().GetQueue();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
result.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetQueue_should_return_a_list_with_items_when_the_queue_has_items()
|
||||||
|
{
|
||||||
|
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"));
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = Mocker.Resolve<SabProvider>().GetQueue();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
result.Should().HaveCount(2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
13
NzbDrone.Core/Model/SabQueueItem.cs
Normal file
13
NzbDrone.Core/Model/SabQueueItem.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -234,6 +234,7 @@
|
|||||||
<Compile Include="Model\Quality.cs" />
|
<Compile Include="Model\Quality.cs" />
|
||||||
<Compile Include="Model\SabnzbdCategoryModel.cs" />
|
<Compile Include="Model\SabnzbdCategoryModel.cs" />
|
||||||
<Compile Include="Model\SabnzbdInfoModel.cs" />
|
<Compile Include="Model\SabnzbdInfoModel.cs" />
|
||||||
|
<Compile Include="Model\SabQueueItem.cs" />
|
||||||
<Compile Include="Model\Twitter\TwitterAuthorizationModel.cs" />
|
<Compile Include="Model\Twitter\TwitterAuthorizationModel.cs" />
|
||||||
<Compile Include="Model\UpdatePackage.cs" />
|
<Compile Include="Model\UpdatePackage.cs" />
|
||||||
<Compile Include="Model\Xbmc\ActionType.cs" />
|
<Compile Include="Model\Xbmc\ActionType.cs" />
|
||||||
|
@ -10,6 +10,7 @@ using Ninject;
|
|||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Core.Model;
|
using NzbDrone.Core.Model;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
|
using NzbDrone.Core.Repository.Quality;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers
|
namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
@ -103,6 +104,34 @@ namespace NzbDrone.Core.Providers
|
|||||||
return false; //Not in Queue
|
return false; //Not in Queue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual List<SabQueueItem> 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<SabQueueItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
public virtual String GetSabTitle(EpisodeParseResult parseResult)
|
||||||
{
|
{
|
||||||
//Handle Full Naming
|
//Handle Full Naming
|
||||||
|
Loading…
Reference in New Issue
Block a user