Fix: Newznab will now use the NZB download link properly.

Fix: Newznab will properly get the size for the NZB.
Fixes bug: ND-30
pull/4/head
Mark McDowall 13 years ago
parent 2303a02a06
commit 783f32a849

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:newznab="http://www.newznab.com/DTD/2010/feeds/attributes/">
<channel>
<atom:link href="http://nzb.su/api?t=tvsearch&amp;cat=5030,5040&amp;apikey=524d129cbd8a329be916e0573d10be5c" rel="self" type="application/rss+xml" />
<title>Nzb.su</title>
<description>Nzb.su Feed</description>
<link>http://nzb.su/</link>
<language>en-gb</language>
<webMaster>root@nzb.su (Nzb.su)</webMaster>
<category></category>
<image>
<url>http://nzb.su/views/images/banner.jpg</url>
<title>Nzb.su</title>
<link>http://nzb.su/</link>
<description>Visit Nzb.su - indexing usenet one part at a time</description>
</image>
<newznab:response offset="0" total="10000" />
<item>
<title>White.Collar.S03E05.720p.HDTV.X264-DIMENSION</title>
<guid isPermaLink="true">http://nzb.su/details/24967ef4c2e26296c65d3bbfa97aa8fe</guid>
<link>http://nzb.su/getnzb/24967ef4c2e26296c65d3bbfa97aa8fe.nzb&amp;i=37292&amp;r=524d129cbd8a329be916e0573d10be5c</link>
<comments>http://nzb.su/details/24967ef4c2e26296c65d3bbfa97aa8fe#comments</comments>
<pubDate>Mon, 27 Feb 2012 11:09:39 -0500</pubDate>
<category>TV &gt; HD</category>
<description>White.Collar.S03E05.720p.HDTV.X264-DIMENSION</description>
<enclosure url="http://nzb.su/getnzb/24967ef4c2e26296c65d3bbfa97aa8fe.nzb&amp;i=37292&amp;r=524d129cbd8a329be916e0573d10be5c" length="1183105773" type="application/x-nzb" />
<newznab:attr name="category" value="5000" />
<newznab:attr name="category" value="5040" />
<newznab:attr name="size" value="1183105773" />
<newznab:attr name="guid" value="24967ef4c2e26296c65d3bbfa97aa8fe" />
</item>
</channel>
</rss>

File diff suppressed because it is too large Load Diff

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Net; using System.Net;
using System.ServiceModel.Syndication; using System.ServiceModel.Syndication;
@ -29,6 +30,7 @@ namespace NzbDrone.Core.Test
[TestCase("nzbsrus.xml")] [TestCase("nzbsrus.xml")]
[TestCase("newzbin.xml")] [TestCase("newzbin.xml")]
[TestCase("nzbmatrix.xml")] [TestCase("nzbmatrix.xml")]
[TestCase("newznab.xml")]
public void parse_feed_xml(string fileName) public void parse_feed_xml(string fileName)
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
@ -356,6 +358,28 @@ namespace NzbDrone.Core.Test
parseResults[0].Size.Should().Be(1793148846); parseResults[0].Size.Should().Be(1793148846);
} }
[Test]
public void size_newznab()
{
WithConfiguredIndexers();
var newznabDefs = Builder<NewznabDefinition>.CreateListOfSize(1)
.All()
.With(n => n.ApiKey = String.Empty)
.Build();
Mocker.GetMock<NewznabProvider>().Setup(s => s.Enabled()).Returns(newznabDefs.ToList());
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\newznab.xml"));
//Act
var parseResults = Mocker.Resolve<Newznab>().FetchRss();
parseResults.Should().HaveCount(1);
parseResults[0].Size.Should().Be(1183105773);
}
[Test] [Test]
public void Server_Unavailable_503_should_not_log_exception() public void Server_Unavailable_503_should_not_log_exception()
@ -396,6 +420,26 @@ namespace NzbDrone.Core.Test
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }
[Test]
public void newznab_link_should_be_link_to_nzb_not_details()
{
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\newznab.xml"));
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
Mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);
var mockIndexer = Mocker.Resolve<MockIndexer>();
var parseResults = mockIndexer.FetchRss();
parseResults.Should().NotBeEmpty();
parseResults.Should().OnlyContain(s => s.NzbUrl.Contains("getnzb"));
parseResults.Should().NotContain(s => s.NzbUrl.Contains("details"));
}
private static void Mark500Inconclusive() private static void Mark500Inconclusive()
{ {
ExceptionVerification.MarkInconclusive(typeof(WebException)); ExceptionVerification.MarkInconclusive(typeof(WebException));

@ -214,6 +214,9 @@
<Content Include="Files\JsonError.txt"> <Content Include="Files\JsonError.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Files\RSS\newznab.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\RSS\newbin_none_english.xml"> <Content Include="Files\RSS\newbin_none_english.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
@ -223,6 +226,9 @@
<Content Include="Files\RSS\SizeParsing\newzbin.xml"> <Content Include="Files\RSS\SizeParsing\newzbin.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Files\RSS\SizeParsing\newznab.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\RSS\SizeParsing\nzbmatrix.xml"> <Content Include="Files\RSS\SizeParsing\nzbmatrix.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>

@ -71,7 +71,7 @@ namespace NzbDrone.Core.Providers.Indexer
protected override string NzbDownloadUrl(SyndicationItem item) protected override string NzbDownloadUrl(SyndicationItem item)
{ {
return item.Id; return item.Links[0].Uri.ToString();
} }
@ -79,8 +79,8 @@ namespace NzbDrone.Core.Providers.Indexer
{ {
if (currentResult != null) if (currentResult != null)
{ {
var sizeString = Regex.Match(item.Summary.Text, @">\d+\.\d{1,2} \w{2}</a>", RegexOptions.IgnoreCase).Value; if (item.Links.Count > 1)
currentResult.Size = Parser.GetReportSize(sizeString); currentResult.Size = item.Links[1].Length;
} }
return currentResult; return currentResult;
@ -89,9 +89,9 @@ namespace NzbDrone.Core.Providers.Indexer
private string[] GetUrls() private string[] GetUrls()
{ {
var urls = new List<string>(); var urls = new List<string>();
var newznzbIndexers = _newznabProvider.Enabled(); var newznabIndexers = _newznabProvider.Enabled();
foreach (var newznabDefinition in newznzbIndexers) foreach (var newznabDefinition in newznabIndexers)
{ {
if (!String.IsNullOrWhiteSpace(newznabDefinition.ApiKey)) if (!String.IsNullOrWhiteSpace(newznabDefinition.ApiKey))
urls.Add(String.Format("{0}/api?t=tvsearch&cat=5030,5040&apikey={1}", newznabDefinition.Url, urls.Add(String.Format("{0}/api?t=tvsearch&cat=5030,5040&apikey={1}", newznabDefinition.Url,

Loading…
Cancel
Save