Fixed: EzRSS Size Parsing

pull/2/head
Keivan Beigi 10 years ago
parent d30eb1b306
commit 23524c238f

@ -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));
}
}
}

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

@ -175,6 +175,22 @@ namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests
ValidateTorrentResult(result, hasSize: true); 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) private void ValidateResult(IList<ReleaseInfo> reports, bool hasSize = false, bool hasInfoUrl = false)
{ {
reports.Should().NotBeEmpty(); 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:"));
}
}
} }
} }

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

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

@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Indexers.KickassTorrents namespace NzbDrone.Core.Indexers.KickassTorrents
@ -9,11 +10,6 @@ namespace NzbDrone.Core.Indexers.KickassTorrents
{ {
public KickassTorrentsSettings Settings { get; set; } public KickassTorrentsSettings Settings { get; set; }
public KickassTorrentsRssParser()
{
}
protected override bool PreProcess(IndexerResponse indexerResponse) protected override bool PreProcess(IndexerResponse indexerResponse)
{ {
if (indexerResponse.HttpResponse.StatusCode == System.Net.HttpStatusCode.NotFound) 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) 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") if (Settings != null && Settings.VerifiedOnly && (string)verified == "0")
{ {

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

Loading…
Cancel
Save