From 23524c238f17fba7e53d91794b4b38ddf36fdd7d Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Mon, 24 Nov 2014 15:16:29 -0800 Subject: [PATCH] Fixed: EzRSS Size Parsing --- .../Extensions/XmlExtentions.cs | 15 ++++++++ src/NzbDrone.Common/NzbDrone.Common.csproj | 2 ++ .../IndexerIntegrationTests.cs | 30 ++++++++-------- .../Indexers/EzrssTorrentRssParser.cs | 36 ++++--------------- .../Indexers/IIndexerRequestGenerator.cs | 5 +-- .../KickassTorrentsRssParser.cs | 8 ++--- .../Indexers/Newznab/NewznabRssParser.cs | 2 -- 7 files changed, 42 insertions(+), 56 deletions(-) create mode 100644 src/NzbDrone.Common/Extensions/XmlExtentions.cs diff --git a/src/NzbDrone.Common/Extensions/XmlExtentions.cs b/src/NzbDrone.Common/Extensions/XmlExtentions.cs new file mode 100644 index 000000000..5e9ffd6db --- /dev/null +++ b/src/NzbDrone.Common/Extensions/XmlExtentions.cs @@ -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 FindDecendants(this XContainer container, string localName) + { + return container.Descendants().Where(c => c.Name.LocalName.Equals(localName, StringComparison.InvariantCultureIgnoreCase)); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Common/NzbDrone.Common.csproj b/src/NzbDrone.Common/NzbDrone.Common.csproj index 0b729ab87..92491e068 100644 --- a/src/NzbDrone.Common/NzbDrone.Common.csproj +++ b/src/NzbDrone.Common/NzbDrone.Common.csproj @@ -57,6 +57,7 @@ ..\packages\NLog.2.1.0\lib\net40\NLog.dll + @@ -129,6 +130,7 @@ + Component diff --git a/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs b/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs index cd2fcd964..8da188370 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs @@ -175,6 +175,22 @@ namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests ValidateTorrentResult(result, hasSize: true); } + + + private void ValidateTorrentResult(IList 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().Should().OnlyContain(c => c.MagnetUrl.StartsWith("magnet:")); + } + } + private void ValidateResult(IList reports, bool hasSize = false, bool hasInfoUrl = false) { reports.Should().NotBeEmpty(); @@ -194,19 +210,5 @@ namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests } } - private void ValidateTorrentResult(IList 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().Should().OnlyContain(c => c.MagnetUrl.StartsWith("magnet:")); - } - } - } } diff --git a/src/NzbDrone.Core/Indexers/EzrssTorrentRssParser.cs b/src/NzbDrone.Core/Indexers/EzrssTorrentRssParser.cs index 405bdc811..8fbede813 100644 --- a/src/NzbDrone.Core/Indexers/EzrssTorrentRssParser.cs +++ b/src/NzbDrone.Core/Indexers/EzrssTorrentRssParser.cs @@ -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; diff --git a/src/NzbDrone.Core/Indexers/IIndexerRequestGenerator.cs b/src/NzbDrone.Core/Indexers/IIndexerRequestGenerator.cs index 4a63d94c6..02ef5ee3e 100644 --- a/src/NzbDrone.Core/Indexers/IIndexerRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/IIndexerRequestGenerator.cs @@ -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 diff --git a/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs b/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs index b2b8392f7..6a314e844 100644 --- a/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs +++ b/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs @@ -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") { diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs index bab522d32..5d0043af3 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs @@ -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;