diff --git a/src/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs b/src/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs index 049677f78..4bca174db 100644 --- a/src/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Common; @@ -13,7 +14,8 @@ namespace NzbDrone.Core.IndexerSearch { public interface IEpisodeSearchService { - void MissingEpisodesAiredAfter(DateTime dateTime); + void MissingEpisodesAiredAfter(DateTime dateTime, IEnumerable grabbed + ); } public class MissingEpisodeSearchService : IEpisodeSearchService, IExecute, IExecute @@ -37,11 +39,12 @@ namespace NzbDrone.Core.IndexerSearch _logger = logger; } - public void MissingEpisodesAiredAfter(DateTime dateTime) + public void MissingEpisodesAiredAfter(DateTime dateTime, IEnumerable grabbed) { var missing = _episodeService.EpisodesBetweenDates(dateTime, DateTime.UtcNow) .Where(e => !e.HasFile && - !_queueService.GetQueue().Select(q => q.Episode.Id).Contains(e.Id)) + !_queueService.GetQueue().Select(q => q.Episode.Id).Contains(e.Id) && + !grabbed.Contains(e.Id)) .ToList(); var downloadedCount = 0; diff --git a/src/NzbDrone.Core/Indexers/RssSyncService.cs b/src/NzbDrone.Core/Indexers/RssSyncService.cs index 07b26bfff..540b4e52e 100644 --- a/src/NzbDrone.Core/Indexers/RssSyncService.cs +++ b/src/NzbDrone.Core/Indexers/RssSyncService.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Core.DecisionEngine; +using NzbDrone.Core.DecisionEngine.Specifications; using NzbDrone.Core.Download; using NzbDrone.Core.IndexerSearch; using NzbDrone.Core.Instrumentation.Extensions; @@ -11,7 +13,7 @@ namespace NzbDrone.Core.Indexers { public interface IRssSyncService { - void Sync(); + List Sync(); } public class RssSyncService : IRssSyncService, IExecute @@ -36,7 +38,7 @@ namespace NzbDrone.Core.Indexers } - public void Sync() + public List Sync() { _logger.ProgressInfo("Starting RSS Sync"); @@ -45,16 +47,18 @@ namespace NzbDrone.Core.Indexers var downloaded = _downloadApprovedReports.DownloadApproved(decisions); _logger.ProgressInfo("RSS Sync Completed. Reports found: {0}, Reports downloaded: {1}", reports.Count, downloaded.Count()); + + return downloaded; } public void Execute(RssSyncCommand message) { - Sync(); + var downloaded = Sync(); if (message.LastExecutionTime.HasValue && DateTime.UtcNow.Subtract(message.LastExecutionTime.Value).TotalHours > 3) { _logger.Info("RSS Sync hasn't run since: {0}. Searching for any missing episodes since then.", message.LastExecutionTime.Value); - _episodeSearchService.MissingEpisodesAiredAfter(message.LastExecutionTime.Value.AddDays(-1)); + _episodeSearchService.MissingEpisodesAiredAfter(message.LastExecutionTime.Value.AddDays(-1), downloaded.SelectMany(d => d.RemoteEpisode.Episodes).Select(e => e.Id)); } } }