From ba12465bb0a08e7737f5e3c8d1dc2ed3c006176d Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 7 Dec 2011 19:54:31 -0800 Subject: [PATCH] Removed code duplication in IndexerBase --- .../Providers/Indexer/IndexerBase.cs | 92 ++++++++----------- 1 file changed, 37 insertions(+), 55 deletions(-) diff --git a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs index 4e350ebd1..621ca966b 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs @@ -85,10 +85,9 @@ public virtual IList FetchRss() var result = new List(); - foreach (var url in Urls) - { - result.AddRange(Fetch(url)); - } + + result = Fetch(Urls); + _logger.Info("Finished processing feeds from " + Name); return result; @@ -98,14 +97,8 @@ public virtual IList FetchSeason(string seriesTitle, int sea { _logger.Debug("Searching {0} for {1}-Season {2}", Name, seriesTitle, seasonNumber); - var result = new List(); - var searchUrls = GetSeasonSearchUrls(GetQueryTitle(seriesTitle), seasonNumber); - - foreach (var url in searchUrls) - { - result.AddRange(Fetch(url)); - } + var result = Fetch(searchUrls); result = result.Where(e => e.CleanTitle == Parser.NormalizeTitle(seriesTitle)).ToList(); @@ -117,14 +110,10 @@ public virtual IList FetchPartialSeason(string seriesTitle, { _logger.Debug("Searching {0} for {1}-Season {2}, Prefix: {3}", Name, seriesTitle, seasonNumber, episodePrefix); - var result = new List(); var searchUrls = GetPartialSeasonSearchUrls(GetQueryTitle(seriesTitle), seasonNumber, episodePrefix); - foreach (var url in searchUrls) - { - result.AddRange(Fetch(url)); - } + var result = Fetch(searchUrls); result = result.Where(e => e.CleanTitle == Parser.NormalizeTitle(seriesTitle)).ToList(); @@ -136,14 +125,9 @@ public virtual IList FetchEpisode(string seriesTitle, int se { _logger.Debug("Searching {0} for {1}-S{2:00}E{3:00}", Name, seriesTitle, seasonNumber, episodeNumber); - var result = new List(); - var searchUrls = GetEpisodeSearchUrls(GetQueryTitle(seriesTitle), seasonNumber, episodeNumber); - foreach (var url in searchUrls) - { - result.AddRange(Fetch(url)); - } + var result = Fetch(searchUrls); result = result.Where(e => e.CleanTitle == Parser.NormalizeTitle(seriesTitle)).ToList(); @@ -156,14 +140,9 @@ public virtual IList FetchDailyEpisode(string seriesTitle, D { _logger.Debug("Searching {0} for {1}-{2}", Name, seriesTitle, airDate.ToShortDateString()); - var result = new List(); - var searchUrls = GetDailyEpisodeSearchUrls(GetQueryTitle(seriesTitle), airDate); - foreach (var url in searchUrls) - { - result.AddRange(Fetch(url)); - } + var result = Fetch(searchUrls); result = result.Where(e => e.CleanTitle == Parser.NormalizeTitle(seriesTitle)).ToList(); @@ -172,40 +151,43 @@ public virtual IList FetchDailyEpisode(string seriesTitle, D } - private IEnumerable Fetch(string url) + private List Fetch(IEnumerable urls) { var result = new List(); - try + foreach (var url in urls) { - _logger.Trace("Downloading RSS " + url); - - var reader = new SyndicationFeedXmlReader(_httpProvider.DownloadStream(url, Credentials)); - var feed = SyndicationFeed.Load(reader).Items; - - foreach (var item in feed) + try { - try - { - var parsedEpisode = ParseFeed(item); - if (parsedEpisode != null) - { - parsedEpisode.NzbUrl = NzbDownloadUrl(item); - parsedEpisode.Indexer = Name; - parsedEpisode.NzbTitle = item.Title.Text; - result.Add(parsedEpisode); - } - } - catch (Exception itemEx) - { - _logger.ErrorException("An error occurred while processing feed item", itemEx); - } + _logger.Trace("Downloading RSS " + url); + var reader = new SyndicationFeedXmlReader(_httpProvider.DownloadStream(url, Credentials)); + var feed = SyndicationFeed.Load(reader).Items; + + foreach (var item in feed) + { + try + { + var parsedEpisode = ParseFeed(item); + if (parsedEpisode != null) + { + parsedEpisode.NzbUrl = NzbDownloadUrl(item); + parsedEpisode.Indexer = Name; + parsedEpisode.NzbTitle = item.Title.Text; + result.Add(parsedEpisode); + } + } + catch (Exception itemEx) + { + _logger.ErrorException("An error occurred while processing feed item", itemEx); + } + + } + } + catch (Exception feedEx) + { + _logger.ErrorException("An error occurred while processing feed", feedEx); } - } - catch (Exception feedEx) - { - _logger.ErrorException("An error occurred while processing feed", feedEx); } return result;