From a22cbfee2fc5526f95f557ddbdbe59e7919fcd34 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 29 Aug 2013 18:32:25 -0700 Subject: [PATCH] handle empty rss response from indexers. --- NzbDrone.Core/Indexers/BasicRssParser.cs | 50 ++++++++++--------- NzbDrone.Core/Indexers/IndexerFetchService.cs | 12 ++++- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/NzbDrone.Core/Indexers/BasicRssParser.cs b/NzbDrone.Core/Indexers/BasicRssParser.cs index d29889248..17963956c 100644 --- a/NzbDrone.Core/Indexers/BasicRssParser.cs +++ b/NzbDrone.Core/Indexers/BasicRssParser.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; +using System.Xml; using System.Xml.Linq; using NLog; using NzbDrone.Core.Parser.Model; @@ -12,7 +13,7 @@ namespace NzbDrone.Core.Indexers { public interface IParseFeed { - IEnumerable Process(Stream source, string url); + IEnumerable Process(string xml, string url); } public class BasicRssParser : IParseFeed @@ -24,34 +25,37 @@ public BasicRssParser() _logger = LogManager.GetCurrentClassLogger(); } - public IEnumerable Process(Stream source, string url) + public IEnumerable Process(string xml, string url) { - var document = XDocument.Load(source); - var items = document.Descendants("item"); - - var result = new List(); - - foreach (var item in items) + using (var xmlTextReader = new XmlTextReader(new StringReader(xml)) { DtdProcessing = DtdProcessing.Ignore }) { - try - { - var reportInfo = ParseFeedItem(item); - if (reportInfo != null) - { - reportInfo.NzbUrl = GetNzbUrl(item); - reportInfo.NzbInfoUrl = GetNzbInfoUrl(item); + var document = XDocument.Load(xmlTextReader); + var items = document.Descendants("item"); - result.Add(reportInfo); + var result = new List(); + + foreach (var item in items) + { + try + { + var reportInfo = ParseFeedItem(item); + if (reportInfo != null) + { + reportInfo.NzbUrl = GetNzbUrl(item); + reportInfo.NzbInfoUrl = GetNzbInfoUrl(item); + + result.Add(reportInfo); + } + } + catch (Exception itemEx) + { + itemEx.Data.Add("Item", item.Title()); + _logger.ErrorException("An error occurred while processing feed item from " + url, itemEx); } } - catch (Exception itemEx) - { - itemEx.Data.Add("Item", item.Title()); - _logger.ErrorException("An error occurred while processing feed item from " + url, itemEx); - } - } - return result; + return result; + } } diff --git a/NzbDrone.Core/Indexers/IndexerFetchService.cs b/NzbDrone.Core/Indexers/IndexerFetchService.cs index 6c46032b6..63a2c5e6b 100644 --- a/NzbDrone.Core/Indexers/IndexerFetchService.cs +++ b/NzbDrone.Core/Indexers/IndexerFetchService.cs @@ -106,8 +106,16 @@ private List Fetch(IIndexer indexer, IEnumerable urls) try { _logger.Trace("Downloading Feed " + url); - var stream = _httpProvider.DownloadStream(url); - result.AddRange(indexer.Parser.Process(stream, url)); + var xml = _httpProvider.DownloadString(url); + if (!string.IsNullOrWhiteSpace(xml)) + { + result.AddRange(indexer.Parser.Process(xml, url)); + } + else + { + _logger.Warn("{0} returned empty response.", url); + } + } catch (WebException webException) {