diff --git a/src/NzbDrone.Core.Test/Files/Indexers/Newznab/newznab_caps.xml b/src/NzbDrone.Core.Test/Files/Indexers/Newznab/newznab_caps.xml
new file mode 100644
index 000000000..f340341ca
--- /dev/null
+++ b/src/NzbDrone.Core.Test/Files/Indexers/Newznab/newznab_caps.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs
new file mode 100644
index 000000000..735fe7b03
--- /dev/null
+++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs
@@ -0,0 +1,68 @@
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+using NzbDrone.Common.Http;
+using NzbDrone.Core.Indexers.Newznab;
+using NzbDrone.Core.Test.Framework;
+
+namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
+{
+ [TestFixture]
+ public class NewznabCapabilitiesProviderFixture : CoreTest
+ {
+ private NewznabSettings _settings;
+ private string _caps;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _settings = new NewznabSettings()
+ {
+ Url = "http://indxer.local"
+ };
+
+ _caps = ReadAllText("Files", "Indexers", "Newznab", "newznab_caps.xml");
+ }
+
+ private void GivenCapsResponse(string caps)
+ {
+ Mocker.GetMock()
+ .Setup(o => o.Get(It.IsAny()))
+ .Returns(r => new HttpResponse(r, new HttpHeader(), caps));
+ }
+
+ [Test]
+ public void should_not_request_same_caps_twice()
+ {
+ GivenCapsResponse(_caps);
+
+ Subject.GetCapabilities(_settings);
+ Subject.GetCapabilities(_settings);
+
+ Mocker.GetMock()
+ .Verify(o => o.Get(It.IsAny()), Times.Once());
+ }
+
+ [Test]
+ public void should_report_pagesize()
+ {
+ GivenCapsResponse(_caps);
+
+ var caps = Subject.GetCapabilities(_settings);
+
+ caps.DefaultPageSize.Should().Be(25);
+ caps.MaxPageSize.Should().Be(60);
+ }
+
+ [Test]
+ public void should_use_default_pagesize_if_missing()
+ {
+ GivenCapsResponse(_caps.Replace("
{
+ private NewznabCapabilities _caps;
+
[SetUp]
public void Setup()
{
@@ -28,9 +30,10 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
}
};
+ _caps = new NewznabCapabilities();
Mocker.GetMock()
.Setup(v => v.GetCapabilities(It.IsAny()))
- .Returns(new NewznabCapabilities());
+ .Returns(_caps);
}
[Test]
@@ -58,5 +61,14 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
releaseInfo.PublishDate.Should().Be(DateTime.Parse("2012/02/27 16:09:39"));
releaseInfo.Size.Should().Be(1183105773);
}
+
+ [Test]
+ public void should_use_pagesize_reported_by_caps()
+ {
+ _caps.MaxPageSize = 30;
+ _caps.DefaultPageSize = 25;
+
+ Subject.PageSize.Should().Be(25);
+ }
}
}
diff --git a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs
index be48f1ecf..8701fdc9a 100644
--- a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs
+++ b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs
@@ -15,6 +15,8 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests
[TestFixture]
public class TorznabFixture : CoreTest
{
+ private NewznabCapabilities _caps;
+
[SetUp]
public void Setup()
{
@@ -28,9 +30,10 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests
}
};
+ _caps = new NewznabCapabilities();
Mocker.GetMock()
.Setup(v => v.GetCapabilities(It.IsAny()))
- .Returns(new NewznabCapabilities());
+ .Returns(_caps);
}
[Test]
@@ -93,5 +96,14 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests
releaseInfo.Seeders.Should().Be(34128);
releaseInfo.Peers.Should().Be(36724);
}
+
+ [Test]
+ public void should_use_pagesize_reported_by_caps()
+ {
+ _caps.MaxPageSize = 30;
+ _caps.DefaultPageSize = 25;
+
+ Subject.PageSize.Should().Be(25);
+ }
}
}
diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
index d5ba99f02..3702c8749 100644
--- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
+++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
@@ -226,6 +226,7 @@
+
@@ -409,6 +410,9 @@
Always
+
+ Always
+
Always
diff --git a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs
index 8bb33c093..c8594cf3e 100644
--- a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs
+++ b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs
@@ -24,7 +24,10 @@ namespace NzbDrone.Core.Indexers.Newznab
}
public override DownloadProtocol Protocol { get { return DownloadProtocol.Usenet; } }
- public override int PageSize { get { return 100; } }
+ public override int PageSize
+ {
+ get { return _capabilitiesProvider.GetCapabilities(Settings).DefaultPageSize; }
+ }
public override IIndexerRequestGenerator GetRequestGenerator()
{
diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs
index a1c30231d..9eaa5b319 100644
--- a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs
+++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs
@@ -5,6 +5,8 @@ namespace NzbDrone.Core.Indexers.Newznab
{
public class NewznabCapabilities
{
+ public int DefaultPageSize { get; set; }
+ public int MaxPageSize { get; set; }
public string[] SupportedSearchParameters { get; set; }
public string[] SupportedTvSearchParameters { get; set; }
public bool SupportsAggregateIdSearch { get; set; }
@@ -12,6 +14,8 @@ namespace NzbDrone.Core.Indexers.Newznab
public NewznabCapabilities()
{
+ DefaultPageSize = 100;
+ MaxPageSize = 100;
SupportedSearchParameters = new[] { "q" };
SupportedTvSearchParameters = new[] { "q", "rid", "season", "ep" }; // This should remain 'rid' for older newznab installs.
SupportsAggregateIdSearch = false;
diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs
index a27641064..9cb004f67 100644
--- a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs
+++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs
@@ -68,6 +68,13 @@ namespace NzbDrone.Core.Indexers.Newznab
var xmlRoot = XDocument.Parse(response.Content).Element("caps");
+ var xmlLimits = xmlRoot.Element("limits");
+ if (xmlLimits != null)
+ {
+ capabilities.DefaultPageSize = int.Parse(xmlLimits.Attribute("default").Value);
+ capabilities.MaxPageSize = int.Parse(xmlLimits.Attribute("max").Value);
+ }
+
var xmlSearching = xmlRoot.Element("searching");
if (xmlSearching != null)
{