From 29ee0ef2bed4616915b14f91adff6c2d0df59c37 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 3 Dec 2014 17:22:14 -0800 Subject: [PATCH] Fixed: EZTV logging generic error when there were no results --- .../BroadcastheNet/BroadcastheNetParser.cs | 8 ++-- .../Indexers/EzrssTorrentRssParser.cs | 19 +++++++++ src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 7 +++- .../Omgwtfnzbs/OmgwtfnzbsRssParser.cs | 1 - src/NzbDrone.Core/Indexers/RssParser.cs | 39 +++++++++---------- .../Indexers/TorrentRssParser.cs | 3 -- 6 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs index d639b56ef..a3a2439d9 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs @@ -16,19 +16,19 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet { var results = new List(); - if (indexerResponse.HttpResponse.StatusCode == System.Net.HttpStatusCode.Unauthorized) + if (indexerResponse.HttpResponse.StatusCode == HttpStatusCode.Unauthorized) { throw new ApiKeyException("API Key invalid or not authorized"); } - else if (indexerResponse.HttpResponse.StatusCode == System.Net.HttpStatusCode.NotFound) + else if (indexerResponse.HttpResponse.StatusCode == HttpStatusCode.NotFound) { throw new IndexerException(indexerResponse, "Indexer API call returned NotFound, the Indexer API may have changed."); } - else if (indexerResponse.HttpResponse.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable) + else if (indexerResponse.HttpResponse.StatusCode == HttpStatusCode.ServiceUnavailable) { throw new RequestLimitReachedException("Cannot do more than 150 API requests per hour."); } - else if (indexerResponse.HttpResponse.StatusCode != System.Net.HttpStatusCode.OK) + else if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) { throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode); } diff --git a/src/NzbDrone.Core/Indexers/EzrssTorrentRssParser.cs b/src/NzbDrone.Core/Indexers/EzrssTorrentRssParser.cs index 8fbede813..c10331478 100644 --- a/src/NzbDrone.Core/Indexers/EzrssTorrentRssParser.cs +++ b/src/NzbDrone.Core/Indexers/EzrssTorrentRssParser.cs @@ -1,7 +1,10 @@ using System; +using System.IO; using System.Linq; +using System.Xml; using System.Xml.Linq; using NzbDrone.Common.Extensions; +using NzbDrone.Core.Indexers.Exceptions; namespace NzbDrone.Core.Indexers { @@ -14,6 +17,22 @@ namespace NzbDrone.Core.Indexers UseEnclosureUrl = true; } + protected override bool PreProcess(IndexerResponse indexerResponse) + { + using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true })) + { + var document = XDocument.Load(xmlTextReader); + var items = GetItems(document).ToList(); + + if (items.Count == 1 && GetTitle(items.First()).Equals("No items exist - Try again later")) + { + throw new IndexerException(indexerResponse, "No results were found"); + } + } + + return base.PreProcess(indexerResponse); + } + protected override Int64 GetSize(XElement item) { var contentLength = item.FindDecendants("contentLength").SingleOrDefault(); diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index 7cb0b1d07..38e08ab79 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -154,7 +154,7 @@ namespace NzbDrone.Core.Indexers } catch (HttpException httpException) { - if ((int)httpException.Response.StatusCode == 429) + if ((int) httpException.Response.StatusCode == 429) { _logger.Warn("API Request Limit reached for {0}", this); } @@ -170,6 +170,11 @@ namespace NzbDrone.Core.Indexers { _logger.Warn("Invalid API Key for {0} {1}", this, url); } + catch (IndexerException ex) + { + var message = String.Format("{0} - {1}", ex.Message, url); + _logger.WarnException(message, ex); + } catch (Exception feedEx) { feedEx.Data.Add("FeedUrl", url); diff --git a/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsRssParser.cs b/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsRssParser.cs index 66d4230ac..497a3cdae 100644 --- a/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsRssParser.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Text.RegularExpressions; using System.Xml.Linq; -using NzbDrone.Common; using NzbDrone.Common.Extensions; using NzbDrone.Core.Indexers.Exceptions; diff --git a/src/NzbDrone.Core/Indexers/RssParser.cs b/src/NzbDrone.Core/Indexers/RssParser.cs index 97a635daa..f3230deb6 100644 --- a/src/NzbDrone.Core/Indexers/RssParser.cs +++ b/src/NzbDrone.Core/Indexers/RssParser.cs @@ -7,7 +7,6 @@ using System.Text.RegularExpressions; using System.Xml; using System.Xml.Linq; using NLog; -using NzbDrone.Common; using NzbDrone.Common.Extensions; using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Indexers.Exceptions; @@ -195,6 +194,25 @@ namespace NzbDrone.Core.Indexers return 0; } + protected IEnumerable GetItems(XDocument document) + { + var root = document.Root; + + if (root == null) + { + return Enumerable.Empty(); + } + + var channel = root.Element("channel"); + + if (channel == null) + { + return Enumerable.Empty(); + } + + return channel.Elements("item"); + } + private static readonly Regex ParseSizeRegex = new Regex(@"(?\d+\.\d{1,2}|\d+\,\d+\.\d{1,2}|\d+)\W?(?[KMG]i?B)", RegexOptions.IgnoreCase | RegexOptions.Compiled); @@ -237,24 +255,5 @@ namespace NzbDrone.Core.Indexers return Convert.ToInt64(result); } - - private IEnumerable GetItems(XDocument document) - { - var root = document.Root; - - if (root == null) - { - return Enumerable.Empty(); - } - - var channel = root.Element("channel"); - - if (channel == null) - { - return Enumerable.Empty(); - } - - return channel.Elements("item"); - } } } diff --git a/src/NzbDrone.Core/Indexers/TorrentRssParser.cs b/src/NzbDrone.Core/Indexers/TorrentRssParser.cs index 37d4d1ae1..14ea6eea3 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRssParser.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRssParser.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Text.RegularExpressions; using System.Xml.Linq; using NzbDrone.Core.Parser.Model;