Fixed: EZTV logging generic error when there were no results

This commit is contained in:
Mark McDowall 2014-12-03 17:22:14 -08:00
parent 0cc4639e65
commit 29ee0ef2be
6 changed files with 48 additions and 29 deletions

View File

@ -16,19 +16,19 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet
{
var results = new List<ReleaseInfo>();
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);
}

View File

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

View File

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

View File

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

View File

@ -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<XElement> GetItems(XDocument document)
{
var root = document.Root;
if (root == null)
{
return Enumerable.Empty<XElement>();
}
var channel = root.Element("channel");
if (channel == null)
{
return Enumerable.Empty<XElement>();
}
return channel.Elements("item");
}
private static readonly Regex ParseSizeRegex = new Regex(@"(?<value>\d+\.\d{1,2}|\d+\,\d+\.\d{1,2}|\d+)\W?(?<unit>[KMG]i?B)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
@ -237,24 +255,5 @@ namespace NzbDrone.Core.Indexers
return Convert.ToInt64(result);
}
private IEnumerable<XElement> GetItems(XDocument document)
{
var root = document.Root;
if (root == null)
{
return Enumerable.Empty<XElement>();
}
var channel = root.Element("channel");
if (channel == null)
{
return Enumerable.Empty<XElement>();
}
return channel.Elements("item");
}
}
}

View File

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