From 99958a822d25c4373f9dd80eada774fca1f49391 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 22 Apr 2013 23:06:05 -0700 Subject: [PATCH] minor sync cleanup. --- .../Indexers/FetchAndParseRssService.cs | 56 +++++++++++++++++++ NzbDrone.Core/Indexers/RssSyncService.cs | 51 ++--------------- .../Jobs/Implementations/RssSyncJob.cs | 8 +-- NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 NzbDrone.Core/Indexers/FetchAndParseRssService.cs diff --git a/NzbDrone.Core/Indexers/FetchAndParseRssService.cs b/NzbDrone.Core/Indexers/FetchAndParseRssService.cs new file mode 100644 index 000000000..7e727c56c --- /dev/null +++ b/NzbDrone.Core/Indexers/FetchAndParseRssService.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using NLog; +using NzbDrone.Core.Parser.Model; + +namespace NzbDrone.Core.Indexers +{ + public interface IFetchAndParseRss + { + List Fetch(); + } + + public class FetchAndParseRssService : IFetchAndParseRss + { + private readonly IIndexerService _indexerService; + private readonly IFetchFeedFromIndexers _feedFetcher; + private readonly Logger _logger; + + public FetchAndParseRssService(IIndexerService indexerService, IFetchFeedFromIndexers feedFetcher, Logger logger) + { + _indexerService = indexerService; + _feedFetcher = feedFetcher; + _logger = logger; + } + + public List Fetch() + { + var result = new List(); + + var indexers = _indexerService.GetAvailableIndexers(); + + if (!indexers.Any()) + { + _logger.Warn("No available indexers. check your configuration."); + return result; + } + + _logger.Debug("Available indexers {0}", indexers.Count); + + Parallel.ForEach(indexers, indexer => + { + var indexerFeed = _feedFetcher.FetchRss(indexer); + + lock (result) + { + result.AddRange(indexerFeed); + } + }); + + _logger.Debug("Found {0} reports", result.Count); + + return result; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/RssSyncService.cs b/NzbDrone.Core/Indexers/RssSyncService.cs index 251cef92f..e99aefdbc 100644 --- a/NzbDrone.Core/Indexers/RssSyncService.cs +++ b/NzbDrone.Core/Indexers/RssSyncService.cs @@ -1,23 +1,18 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using NLog; using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Download; -using NzbDrone.Core.Model; -using NzbDrone.Core.Parser; -using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Indexers { - public interface ISyncRss + public interface IRssSyncService { void Sync(); } - public class RssSyncService : ISyncRss + public class RssSyncService : IRssSyncService { private readonly IFetchAndParseRss _rssFetcherAndParser; private readonly IMakeDownloadDecision _downloadDecisionMaker; @@ -40,6 +35,8 @@ namespace NzbDrone.Core.Indexers var parseResults = _rssFetcherAndParser.Fetch(); var decisions = _downloadDecisionMaker.GetRssDecision(parseResults); + //TODO: this will download multiple of same episode if they show up in RSS. need to + var qualifiedReports = decisions .Where(c => c.Approved) .Select(c => c.Episode) @@ -48,6 +45,7 @@ namespace NzbDrone.Core.Indexers .ThenBy(c => c.Report.Age); + foreach (var episodeParseResult in qualifiedReports) { try @@ -60,44 +58,7 @@ namespace NzbDrone.Core.Indexers } } - _logger.Info("RSS Sync Completed. Reports found {0}, Fetches attempted {1}", parseResults.Count, qualifiedReports); - } - } - - - public interface IFetchAndParseRss - { - List Fetch(); - } - - public class FetchAndParseRssService : IFetchAndParseRss - { - private readonly IIndexerService _indexerService; - private readonly IFetchFeedFromIndexers _feedFetcher; - - public FetchAndParseRssService(IIndexerService indexerService, IFetchFeedFromIndexers feedFetcher) - { - _indexerService = indexerService; - _feedFetcher = feedFetcher; - } - - public List Fetch() - { - var result = new List(); - - var indexers = _indexerService.GetAvailableIndexers(); - - Parallel.ForEach(indexers, indexer => - { - var indexerFeed = _feedFetcher.FetchRss(indexer); - - lock (result) - { - result.AddRange(indexerFeed); - } - }); - - return result; + _logger.Info("RSS Sync Completed. Reports found: {0}, Fetches attempted: {1}", parseResults.Count, qualifiedReports.Count()); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/RssSyncJob.cs b/NzbDrone.Core/Jobs/Implementations/RssSyncJob.cs index 2b11a82a8..72b8ca6c9 100644 --- a/NzbDrone.Core/Jobs/Implementations/RssSyncJob.cs +++ b/NzbDrone.Core/Jobs/Implementations/RssSyncJob.cs @@ -7,13 +7,13 @@ namespace NzbDrone.Core.Jobs.Implementations { public class RssSyncJob : IJob { - private readonly ISyncRss _syncRssService; + private readonly IRssSyncService _rssSyncServiceService; private readonly IConfigService _configService; - public RssSyncJob(ISyncRss syncRssService, IConfigService configService) + public RssSyncJob(IRssSyncService rssSyncServiceService, IConfigService configService) { - _syncRssService = syncRssService; + _rssSyncServiceService = rssSyncServiceService; _configService = configService; } @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Jobs.Implementations public void Start(ProgressNotification notification, dynamic options) { - _syncRssService.Sync(); + _rssSyncServiceService.Sync(); } } } \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index e7fb4328e..c09d8c947 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -234,6 +234,7 @@ +