Fixed: Sabnzbd 2.0 api compatibility.

closes #1775
pull/6/head
Taloth Saldono 8 years ago
parent abd70f5381
commit 70f7404499

@ -23,6 +23,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
private SabnzbdHistory _failed;
private SabnzbdHistory _completed;
private SabnzbdConfig _config;
private SabnzbdFullStatus _fullStatus;
[SetUp]
public void Setup()
@ -103,6 +104,15 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
Mocker.GetMock<ISabnzbdProxy>()
.Setup(s => s.GetConfig(It.IsAny<SabnzbdSettings>()))
.Returns(_config);
_fullStatus = new SabnzbdFullStatus
{
CompleteDir = @"Y:\nzbget\root\complete".AsOsAgnostic()
};
Mocker.GetMock<ISabnzbdProxy>()
.Setup(s => s.GetFullStatus(It.IsAny<SabnzbdSettings>()))
.Returns(_fullStatus);
}
protected void GivenFailedDownload()
@ -386,12 +396,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
result.OutputPath.Should().Be(@"C:\sorted\somewhere\asdfasdf\asdfasdf.mkv".AsOsAgnostic());
}
[TestCase(@"Y:\nzbget\root", @"completed\downloads", @"vv", @"Y:\nzbget\root\completed\downloads\vv")]
[TestCase(@"Y:\nzbget\root", @"completed", @"vv", @"Y:\nzbget\root\completed\vv")]
[TestCase(@"/nzbget/root", @"completed/downloads", @"vv", @"/nzbget/root/completed/downloads/vv")]
[TestCase(@"/nzbget/root", @"completed", @"vv", @"/nzbget/root/completed/vv")]
public void should_return_status_with_outputdir(string rootFolder, string completeDir, string categoryDir, string expectedDir)
[TestCase(@"Y:\nzbget\root", @"completed\downloads", @"vv", @"Y:\nzbget\root\completed\downloads", @"Y:\nzbget\root\completed\downloads\vv")]
[TestCase(@"Y:\nzbget\root", @"completed", @"vv", @"Y:\nzbget\root\completed", @"Y:\nzbget\root\completed\vv")]
[TestCase(@"/nzbget/root", @"completed/downloads", @"vv", @"/nzbget/root/completed/downloads", @"/nzbget/root/completed/downloads/vv")]
[TestCase(@"/nzbget/root", @"completed", @"vv", @"/nzbget/root/completed", @"/nzbget/root/completed/vv")]
public void should_return_status_with_outputdir_for_version_lt_2(string rootFolder, string completeDir, string categoryDir, string fullCompleteDir, string fullCategoryDir)
{
_fullStatus.CompleteDir = null;
_queued.DefaultRootFolder = rootFolder;
_config.Misc.complete_dir = completeDir;
_config.Categories.First().Dir = categoryDir;
@ -402,7 +413,27 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
result.IsLocalhost.Should().BeTrue();
result.OutputRootFolders.Should().NotBeNull();
result.OutputRootFolders.First().Should().Be(expectedDir);
result.OutputRootFolders.First().Should().Be(fullCategoryDir);
}
[TestCase(@"Y:\nzbget\root", @"completed\downloads", @"vv", @"Y:\nzbget\root\completed\downloads", @"Y:\nzbget\root\completed\downloads\vv")]
[TestCase(@"Y:\nzbget\root", @"completed", @"vv", @"Y:\nzbget\root\completed", @"Y:\nzbget\root\completed\vv")]
[TestCase(@"/nzbget/root", @"completed/downloads", @"vv", @"/nzbget/root/completed/downloads", @"/nzbget/root/completed/downloads/vv")]
[TestCase(@"/nzbget/root", @"completed", @"vv", @"/nzbget/root/completed", @"/nzbget/root/completed/vv")]
public void should_return_status_with_outputdir_for_version_gte_2(string rootFolder, string completeDir, string categoryDir, string fullCompleteDir, string fullCategoryDir)
{
_fullStatus.CompleteDir = fullCompleteDir;
_queued.DefaultRootFolder = null;
_config.Misc.complete_dir = completeDir;
_config.Categories.First().Dir = categoryDir;
GivenQueue(null);
var result = Subject.GetStatus();
result.IsLocalhost.Should().BeTrue();
result.OutputRootFolders.Should().NotBeNull();
result.OutputRootFolders.First().Should().Be(fullCategoryDir);
}
[Test]

@ -0,0 +1,7 @@
namespace NzbDrone.Core.Download.Clients.Sabnzbd.Responses
{
public class SabnzbdFullStatusResponse
{
public SabnzbdFullStatus Status { get; set; }
}
}

@ -219,12 +219,20 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
var completeDir = new OsPath(config.Misc.complete_dir);
if (!completeDir.IsRooted)
{
if (HasVersion(2, 0))
{
var status = _proxy.GetFullStatus(Settings);
completeDir = new OsPath(status.CompleteDir);
}
else
{
var queue = _proxy.GetQueue(0, 1, Settings);
var defaultRootFolder = new OsPath(queue.DefaultRootFolder);
completeDir = defaultRootFolder + completeDir;
}
}
foreach (var category in config.Categories)
{

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace NzbDrone.Core.Download.Clients.Sabnzbd
{
public class SabnzbdFullStatus
{
// Added in Sabnzbd 2.0.0, my_home was previously in &mode=queue.
// This is the already resolved completedir path.
[JsonProperty(PropertyName = "completedir")]
public string CompleteDir { get; set; }
}
}

@ -15,6 +15,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
void RemoveFrom(string source, string id,bool deleteData, SabnzbdSettings settings);
string GetVersion(SabnzbdSettings settings);
SabnzbdConfig GetConfig(SabnzbdSettings settings);
SabnzbdFullStatus GetFullStatus(SabnzbdSettings settings);
SabnzbdQueue GetQueue(int start, int limit, SabnzbdSettings settings);
SabnzbdHistory GetHistory(int start, int limit, string category, SabnzbdSettings settings);
string RetryDownload(string id, SabnzbdSettings settings);
@ -84,6 +85,16 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
return response.Config;
}
public SabnzbdFullStatus GetFullStatus(SabnzbdSettings settings)
{
var request = BuildRequest("fullstatus", settings);
request.AddQueryParam("skip_dashboard", "1");
var response = Json.Deserialize<SabnzbdFullStatusResponse>(ProcessRequest(request, settings));
return response.Status;
}
public SabnzbdQueue GetQueue(int start, int limit, SabnzbdSettings settings)
{
var request = BuildRequest("queue", settings);

@ -5,6 +5,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
{
public class SabnzbdQueue
{
// Removed in Sabnzbd 2.0.0, see mode=fullstatus instead.
[JsonProperty(PropertyName = "my_home")]
public string DefaultRootFolder { get; set; }

@ -438,6 +438,7 @@
<Compile Include="Download\Clients\Sabnzbd\JsonConverters\SabnzbdPriorityTypeConverter.cs" />
<Compile Include="Download\Clients\Sabnzbd\JsonConverters\SabnzbdStringArrayConverter.cs" />
<Compile Include="Download\Clients\Sabnzbd\JsonConverters\SabnzbdQueueTimeConverter.cs" />
<Compile Include="Download\Clients\Sabnzbd\Responses\SabnzbdFullStatusResponse.cs" />
<Compile Include="Download\Clients\Sabnzbd\Responses\SabnzbdRetryResponse.cs" />
<Compile Include="Download\Clients\Sabnzbd\Responses\SabnzbdAddResponse.cs" />
<Compile Include="Download\Clients\Sabnzbd\Responses\SabnzbdCategoryResponse.cs" />
@ -446,6 +447,7 @@
<Compile Include="Download\Clients\Sabnzbd\Sabnzbd.cs" />
<Compile Include="Download\Clients\Sabnzbd\SabnzbdCategory.cs" />
<Compile Include="Download\Clients\Sabnzbd\SabnzbdDownloadStatus.cs" />
<Compile Include="Download\Clients\Sabnzbd\SabnzbdFullStatus.cs" />
<Compile Include="Download\Clients\Sabnzbd\SabnzbdHistory.cs" />
<Compile Include="Download\Clients\Sabnzbd\SabnzbdHistoryItem.cs" />
<Compile Include="Download\Clients\Sabnzbd\SabnzbdJsonError.cs" />

Loading…
Cancel
Save