Fixed: EzRSS Size Parsing

This commit is contained in:
Keivan Beigi 2014-11-24 15:16:29 -08:00
parent d30eb1b306
commit 23524c238f
7 changed files with 42 additions and 56 deletions

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace NzbDrone.Common.Extensions
{
public static class XmlExtentions
{
public static IEnumerable<XElement> FindDecendants(this XContainer container, string localName)
{
return container.Descendants().Where(c => c.Name.LocalName.Equals(localName, StringComparison.InvariantCultureIgnoreCase));
}
}
}

View File

@ -57,6 +57,7 @@
<HintPath>..\packages\NLog.2.1.0\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="ArchiveService.cs" />
@ -129,6 +130,7 @@
<Compile Include="Extensions\Base64Extentions.cs" />
<Compile Include="Extensions\Int64Extensions.cs" />
<Compile Include="Extensions\StreamExtensions.cs" />
<Compile Include="Extensions\XmlExtentions.cs" />
<Compile Include="HashUtil.cs" />
<Compile Include="Http\GZipWebClient.cs">
<SubType>Component</SubType>

View File

@ -175,6 +175,22 @@ namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests
ValidateTorrentResult(result, hasSize: true);
}
private void ValidateTorrentResult(IList<ReleaseInfo> reports, bool hasSize = false, bool hasInfoUrl = false, bool hasMagnet = false)
{
reports.Should().OnlyContain(c => c.GetType() == typeof(TorrentInfo));
ValidateResult(reports, hasSize, hasInfoUrl);
reports.Should().OnlyContain(c => c.DownloadProtocol == DownloadProtocol.Torrent);
if (hasMagnet)
{
reports.Cast<TorrentInfo>().Should().OnlyContain(c => c.MagnetUrl.StartsWith("magnet:"));
}
}
private void ValidateResult(IList<ReleaseInfo> reports, bool hasSize = false, bool hasInfoUrl = false)
{
reports.Should().NotBeEmpty();
@ -194,19 +210,5 @@ namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests
}
}
private void ValidateTorrentResult(IList<ReleaseInfo> reports, bool hasSize = false, bool hasInfoUrl = false, bool hasMagnet = false)
{
reports.Should().OnlyContain(c => c.GetType() == typeof(TorrentInfo));
ValidateResult(reports, hasSize, hasInfoUrl);
reports.Should().OnlyContain(c => c.DownloadProtocol == DownloadProtocol.Torrent);
if (hasMagnet)
{
reports.Cast<TorrentInfo>().Should().OnlyContain(c => c.MagnetUrl.StartsWith("magnet:"));
}
}
}
}

View File

@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Indexers
{
public class EzrssTorrentRssParser : TorrentRssParser
{
public const String ns = "{http://xmlns.ezrss.it/0.1/}";
public EzrssTorrentRssParser()
{
UseGuidInfoUrl = true;
@ -18,25 +14,9 @@ namespace NzbDrone.Core.Indexers
UseEnclosureUrl = true;
}
protected virtual XElement GetEzrssElement(XElement item, String name)
{
var element = item.Element(ns + name);
if (element == null)
{
element = item.Element(ns + "torrent");
if (element != null)
{
element = element.Element(ns + name);
}
}
return element;
}
protected override Int64 GetSize(XElement item)
{
var contentLength = GetEzrssElement(item, "contentLength");
var contentLength = item.FindDecendants("contentLength").SingleOrDefault();
if (contentLength != null)
{
@ -48,22 +28,19 @@ namespace NzbDrone.Core.Indexers
protected override String GetInfoHash(XElement item)
{
var infoHash = GetEzrssElement(item, "infoHash");
var infoHash = item.FindDecendants("infoHash").SingleOrDefault();
return (String)infoHash;
}
protected override String GetMagnetUrl(XElement item)
{
var magnetURI = GetEzrssElement(item, "magnetURI");
var magnetURI = item.FindDecendants("magnetURI").SingleOrDefault();
return (String)magnetURI;
}
protected override Int32? GetSeeders(XElement item)
{
var seeds = GetEzrssElement(item, "seeds");
var seeds = item.FindDecendants("seeds").SingleOrDefault();
if (seeds != null)
{
return (Int32)seeds;
@ -74,8 +51,7 @@ namespace NzbDrone.Core.Indexers
protected override Int32? GetPeers(XElement item)
{
var peers = GetEzrssElement(item, "peers");
var peers = item.FindDecendants("peers").SingleOrDefault();
if (peers != null)
{
return (Int32)peers;

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using NzbDrone.Core.IndexerSearch.Definitions;
namespace NzbDrone.Core.Indexers

View File

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Xml.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Indexers.KickassTorrents
@ -9,11 +10,6 @@ namespace NzbDrone.Core.Indexers.KickassTorrents
{
public KickassTorrentsSettings Settings { get; set; }
public KickassTorrentsRssParser()
{
}
protected override bool PreProcess(IndexerResponse indexerResponse)
{
if (indexerResponse.HttpResponse.StatusCode == System.Net.HttpStatusCode.NotFound)
@ -26,7 +22,7 @@ namespace NzbDrone.Core.Indexers.KickassTorrents
protected override ReleaseInfo PostProcess(XElement item, ReleaseInfo releaseInfo)
{
var verified = GetEzrssElement(item, "verified");
var verified = item.FindDecendants("verified").SingleOrDefault();
if (Settings != null && Settings.VerifiedOnly && (string)verified == "0")
{

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using NzbDrone.Common;
using NzbDrone.Core.Indexers.Exceptions;