From bac51706aeaa88a3f9274e24bb8ba249f1307bab Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 5 Aug 2013 22:06:58 -0700 Subject: [PATCH] minor feed fetch cleanup. --- NzbDrone.Core/Indexers/IndexerFetchService.cs | 13 +++++------- NzbDrone.Core/Indexers/Newznab/Newznab.cs | 6 +++--- .../Indexers/Newznab/NewznabParser.cs | 11 ++-------- NzbDrone.Core/Indexers/XElementExtensions.cs | 20 ++++++------------- NzbDrone.Core/NzbDrone.Core.csproj | 1 - 5 files changed, 16 insertions(+), 35 deletions(-) diff --git a/NzbDrone.Core/Indexers/IndexerFetchService.cs b/NzbDrone.Core/Indexers/IndexerFetchService.cs index 4d8bea234..4d020002d 100644 --- a/NzbDrone.Core/Indexers/IndexerFetchService.cs +++ b/NzbDrone.Core/Indexers/IndexerFetchService.cs @@ -94,16 +94,13 @@ namespace NzbDrone.Core.Indexers { var result = new List(); - var body = "......"; - foreach (var url in urls) { try { - _logger.Trace("Downloading Feed " + url); - body = _httpProvider.DownloadString(url); - var stream = _httpProvider.DownloadStream(url); - result.AddRange(indexer.Parser.Process(stream)); + _logger.Trace("Downloading Feed " + url); + var stream = _httpProvider.DownloadStream(url); + result.AddRange(indexer.Parser.Process(stream)); } catch (WebException webException) { @@ -114,13 +111,13 @@ namespace NzbDrone.Core.Indexers else { 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) { 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); } } diff --git a/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 0f5261448..2601a08a6 100644 --- a/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -11,7 +11,7 @@ namespace NzbDrone.Core.Indexers.Newznab { get { - return new NewznabParser(this); + return new NewznabParser(); } } @@ -26,7 +26,7 @@ namespace NzbDrone.Core.Indexers.Newznab Enable = false, Name = "Nzbs.org", Implementation = GetType().Name, - Settings = GetSettings("http://nzbs.org", new List{ 5000 }) + Settings = GetSettings("http://nzbs.org", new List { 5000 }) }); @@ -70,7 +70,7 @@ namespace NzbDrone.Core.Indexers.Newznab //Todo: We should be able to update settings on start if (Name.Equals("nzbs.org", StringComparison.InvariantCultureIgnoreCase)) { - Settings.Categories = new List{ 5000 }; + Settings.Categories = new List { 5000 }; } var url = String.Format("{0}/api?t=tvsearch&cat={1}", Settings.Url.TrimEnd('/'), String.Join(",", Settings.Categories)); diff --git a/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs b/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs index 10a2fc036..e04fe077f 100644 --- a/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs +++ b/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs @@ -8,14 +8,7 @@ namespace NzbDrone.Core.Indexers.Newznab { public class NewznabParser : BasicRssParser { - private static XNamespace NEWZNAB = "http://www.newznab.com/DTD/2010/feeds/attributes/"; - - private readonly Newznab _newznabIndexer; - - public NewznabParser(Newznab newznabIndexer) - { - _newznabIndexer = newznabIndexer; - } + private static readonly XNamespace NewznabNamespace = "http://www.newznab.com/DTD/2010/feeds/attributes/"; protected override string GetNzbInfoUrl(XElement item) { @@ -26,7 +19,7 @@ namespace NzbDrone.Core.Indexers.Newznab { 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"); currentResult.Size = Convert.ToInt64(sizeElement.Attribute("value").Value); diff --git a/NzbDrone.Core/Indexers/XElementExtensions.cs b/NzbDrone.Core/Indexers/XElementExtensions.cs index b04239900..00bc469a9 100644 --- a/NzbDrone.Core/Indexers/XElementExtensions.cs +++ b/NzbDrone.Core/Indexers/XElementExtensions.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.Odbc; using System.Linq; -using System.Text; using System.Xml.Linq; namespace NzbDrone.Core.Indexers @@ -11,38 +9,32 @@ namespace NzbDrone.Core.Indexers { public static string Title(this XElement item) { - return TryGetValue(item, "title", "Unknown"); + return item.TryGetValue("title", "Unknown"); } public static DateTime PublishDate(this XElement item) { - return DateTime.Parse(TryGetValue(item, "pubDate")); + return DateTime.Parse(item.TryGetValue("pubDate")); } public static List Links(this XElement item) { - var result = new List(); var elements = item.Elements("link"); - foreach (var link in elements) - { - result.Add(link.Value); - } - - return result; + return elements.Select(link => link.Value).ToList(); } public static string Description(this XElement item) { - return TryGetValue(item, "description"); + return item.TryGetValue("description"); } 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); diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 70e616af1..3b60e5f03 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -104,7 +104,6 @@ True -