minor feed fetch cleanup.

pull/3113/head
kay.one 11 years ago
parent 8f1127b57e
commit bac51706ae

@ -94,16 +94,13 @@ namespace NzbDrone.Core.Indexers
{ {
var result = new List<ReportInfo>(); var result = new List<ReportInfo>();
var body = "......";
foreach (var url in urls) foreach (var url in urls)
{ {
try try
{ {
_logger.Trace("Downloading Feed " + url); _logger.Trace("Downloading Feed " + url);
body = _httpProvider.DownloadString(url); var stream = _httpProvider.DownloadStream(url);
var stream = _httpProvider.DownloadStream(url); result.AddRange(indexer.Parser.Process(stream));
result.AddRange(indexer.Parser.Process(stream));
} }
catch (WebException webException) catch (WebException webException)
{ {
@ -114,13 +111,13 @@ namespace NzbDrone.Core.Indexers
else else
{ {
webException.Data.Add("FeedUrl", url); webException.Data.Add("FeedUrl", url);
_logger.WarnException("An error occurred while processing feed. " + url + " " + body, webException); _logger.WarnException("An error occurred while processing feed. " + url, webException);
} }
} }
catch (Exception feedEx) catch (Exception feedEx)
{ {
feedEx.Data.Add("FeedUrl", url); feedEx.Data.Add("FeedUrl", url);
_logger.ErrorException("An error occurred while processing feed. " + url + " " + body, feedEx); _logger.ErrorException("An error occurred while processing feed. " + url, feedEx);
} }
} }

@ -11,7 +11,7 @@ namespace NzbDrone.Core.Indexers.Newznab
{ {
get get
{ {
return new NewznabParser(this); return new NewznabParser();
} }
} }
@ -26,7 +26,7 @@ namespace NzbDrone.Core.Indexers.Newznab
Enable = false, Enable = false,
Name = "Nzbs.org", Name = "Nzbs.org",
Implementation = GetType().Name, Implementation = GetType().Name,
Settings = GetSettings("http://nzbs.org", new List<Int32>{ 5000 }) Settings = GetSettings("http://nzbs.org", new List<Int32> { 5000 })
}); });
@ -70,7 +70,7 @@ namespace NzbDrone.Core.Indexers.Newznab
//Todo: We should be able to update settings on start //Todo: We should be able to update settings on start
if (Name.Equals("nzbs.org", StringComparison.InvariantCultureIgnoreCase)) if (Name.Equals("nzbs.org", StringComparison.InvariantCultureIgnoreCase))
{ {
Settings.Categories = new List<int>{ 5000 }; Settings.Categories = new List<int> { 5000 };
} }
var url = String.Format("{0}/api?t=tvsearch&cat={1}", Settings.Url.TrimEnd('/'), String.Join(",", Settings.Categories)); var url = String.Format("{0}/api?t=tvsearch&cat={1}", Settings.Url.TrimEnd('/'), String.Join(",", Settings.Categories));

@ -8,14 +8,7 @@ namespace NzbDrone.Core.Indexers.Newznab
{ {
public class NewznabParser : BasicRssParser public class NewznabParser : BasicRssParser
{ {
private static XNamespace NEWZNAB = "http://www.newznab.com/DTD/2010/feeds/attributes/"; private static readonly XNamespace NewznabNamespace = "http://www.newznab.com/DTD/2010/feeds/attributes/";
private readonly Newznab _newznabIndexer;
public NewznabParser(Newznab newznabIndexer)
{
_newznabIndexer = newznabIndexer;
}
protected override string GetNzbInfoUrl(XElement item) protected override string GetNzbInfoUrl(XElement item)
{ {
@ -26,7 +19,7 @@ namespace NzbDrone.Core.Indexers.Newznab
{ {
if (currentResult != null) if (currentResult != null)
{ {
var attributes = item.Elements(NEWZNAB + "attr"); var attributes = item.Elements(NewznabNamespace + "attr");
var sizeElement = attributes.Single(e => e.Attribute("name").Value == "size"); var sizeElement = attributes.Single(e => e.Attribute("name").Value == "size");
currentResult.Size = Convert.ToInt64(sizeElement.Attribute("value").Value); currentResult.Size = Convert.ToInt64(sizeElement.Attribute("value").Value);

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.Odbc;
using System.Linq; using System.Linq;
using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
namespace NzbDrone.Core.Indexers namespace NzbDrone.Core.Indexers
@ -11,38 +9,32 @@ namespace NzbDrone.Core.Indexers
{ {
public static string Title(this XElement item) public static string Title(this XElement item)
{ {
return TryGetValue(item, "title", "Unknown"); return item.TryGetValue("title", "Unknown");
} }
public static DateTime PublishDate(this XElement item) public static DateTime PublishDate(this XElement item)
{ {
return DateTime.Parse(TryGetValue(item, "pubDate")); return DateTime.Parse(item.TryGetValue("pubDate"));
} }
public static List<String> Links(this XElement item) public static List<String> Links(this XElement item)
{ {
var result = new List<String>();
var elements = item.Elements("link"); var elements = item.Elements("link");
foreach (var link in elements) return elements.Select(link => link.Value).ToList();
{
result.Add(link.Value);
}
return result;
} }
public static string Description(this XElement item) public static string Description(this XElement item)
{ {
return TryGetValue(item, "description"); return item.TryGetValue("description");
} }
public static string Comments(this XElement item) public static string Comments(this XElement item)
{ {
return TryGetValue(item, "comments"); return item.TryGetValue("comments");
} }
private static string TryGetValue(XElement item, string elementName, string defaultValue = "") private static string TryGetValue(this XElement item, string elementName, string defaultValue = "")
{ {
var element = item.Element(elementName); var element = item.Element(elementName);

@ -104,7 +104,6 @@
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Web" /> <Reference Include="System.Web" />
<Reference Include="System.XML" /> <Reference Include="System.XML" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />

Loading…
Cancel
Save