diff --git a/src/NzbDrone.Core.Test/IndexerSearchTests/NzbSearchServiceFixture.cs b/src/NzbDrone.Core.Test/IndexerSearchTests/NzbSearchServiceFixture.cs index 8ea33ad65..bdfc6afa7 100644 --- a/src/NzbDrone.Core.Test/IndexerSearchTests/NzbSearchServiceFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerSearchTests/NzbSearchServiceFixture.cs @@ -138,7 +138,7 @@ public void scene_seasonsearch() var allCriteria = WatchForSearchCriteria(); - Subject.SeasonSearch(_xemSeries.Id, 1); + Subject.SeasonSearch(_xemSeries.Id, 1, false); var criteria = allCriteria.OfType().ToList(); @@ -153,7 +153,7 @@ public void scene_seasonsearch_should_search_multiple_seasons() var allCriteria = WatchForSearchCriteria(); - Subject.SeasonSearch(_xemSeries.Id, 2); + Subject.SeasonSearch(_xemSeries.Id, 2, false); var criteria = allCriteria.OfType().ToList(); @@ -169,7 +169,7 @@ public void scene_seasonsearch_should_search_single_episode_if_possible() var allCriteria = WatchForSearchCriteria(); - Subject.SeasonSearch(_xemSeries.Id, 4); + Subject.SeasonSearch(_xemSeries.Id, 4, false); var criteria1 = allCriteria.OfType().ToList(); var criteria2 = allCriteria.OfType().ToList(); @@ -189,7 +189,7 @@ public void scene_seasonsearch_should_use_seasonnumber_if_no_scene_number_is_ava var allCriteria = WatchForSearchCriteria(); - Subject.SeasonSearch(_xemSeries.Id, 7); + Subject.SeasonSearch(_xemSeries.Id, 7, false); var criteria = allCriteria.OfType().ToList(); @@ -202,11 +202,12 @@ public void season_search_for_anime_should_search_for_each_monitored_episode() { WithEpisodes(); _xemSeries.SeriesType = SeriesTypes.Anime; + _xemEpisodes.ForEach(e => e.EpisodeFileId = 0); var seasonNumber = 1; var allCriteria = WatchForSearchCriteria(); - Subject.SeasonSearch(_xemSeries.Id, seasonNumber); + Subject.SeasonSearch(_xemSeries.Id, seasonNumber, true); var criteria = allCriteria.OfType().ToList(); @@ -219,11 +220,29 @@ public void season_search_for_anime_should_not_search_for_unmonitored_episodes() WithEpisodes(); _xemSeries.SeriesType = SeriesTypes.Anime; _xemEpisodes.ForEach(e => e.Monitored = false); + _xemEpisodes.ForEach(e => e.EpisodeFileId = 0); var seasonNumber = 1; var allCriteria = WatchForSearchCriteria(); - Subject.SeasonSearch(_xemSeries.Id, seasonNumber); + Subject.SeasonSearch(_xemSeries.Id, seasonNumber, true); + + var criteria = allCriteria.OfType().ToList(); + + criteria.Count.Should().Be(0); + } + + [Test] + public void season_search_for_anime_should_not_search_for_episodes_with_files() + { + WithEpisodes(); + _xemSeries.SeriesType = SeriesTypes.Anime; + _xemEpisodes.ForEach(e => e.EpisodeFileId = 1); + + var seasonNumber = 1; + var allCriteria = WatchForSearchCriteria(); + + Subject.SeasonSearch(_xemSeries.Id, seasonNumber, true); var criteria = allCriteria.OfType().ToList(); diff --git a/src/NzbDrone.Core.Test/IndexerSearchTests/SeriesSearchServiceFixture.cs b/src/NzbDrone.Core.Test/IndexerSearchTests/SeriesSearchServiceFixture.cs index 3b3f15216..f1c0446e0 100644 --- a/src/NzbDrone.Core.Test/IndexerSearchTests/SeriesSearchServiceFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerSearchTests/SeriesSearchServiceFixture.cs @@ -32,7 +32,7 @@ public void Setup() .Returns(_series); Mocker.GetMock() - .Setup(s => s.SeasonSearch(_series.Id, It.IsAny())) + .Setup(s => s.SeasonSearch(_series.Id, It.IsAny(), false)) .Returns(new List()); Mocker.GetMock() @@ -52,7 +52,7 @@ public void should_only_include_monitored_seasons() Subject.Execute(new SeriesSearchCommand{ SeriesId = _series.Id }); Mocker.GetMock() - .Verify(v => v.SeasonSearch(_series.Id, It.IsAny()), Times.Exactly(_series.Seasons.Count(s => s.Monitored))); + .Verify(v => v.SeasonSearch(_series.Id, It.IsAny(), false), Times.Exactly(_series.Seasons.Count(s => s.Monitored))); } [Test] @@ -68,9 +68,9 @@ public void should_start_with_lower_seasons_first() }; Mocker.GetMock() - .Setup(s => s.SeasonSearch(_series.Id, It.IsAny())) + .Setup(s => s.SeasonSearch(_series.Id, It.IsAny(), false)) .Returns(new List()) - .Callback((seriesId, seasonNumber) => seasonOrder.Add(seasonNumber)); + .Callback((seriesId, seasonNumber, missingOnly) => seasonOrder.Add(seasonNumber)); Subject.Execute(new SeriesSearchCommand { SeriesId = _series.Id }); diff --git a/src/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs b/src/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs index 72459d7c6..d5eacd707 100644 --- a/src/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs @@ -80,7 +80,7 @@ private void SearchForMissingEpisodes(List episodes) if (season.Count() > 1) { - decisions = _nzbSearchService.SeasonSearch(series.Key, season.Key); + decisions = _nzbSearchService.SeasonSearch(series.Key, season.Key, true); } else diff --git a/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs b/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs index 881fa99b1..e56d1c734 100644 --- a/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs @@ -19,7 +19,7 @@ public interface ISearchForNzb { List EpisodeSearch(int episodeId); List EpisodeSearch(Episode episode); - List SeasonSearch(int seriesId, int seasonNumber); + List SeasonSearch(int seriesId, int seasonNumber, bool missingOnly); } public class NzbSearchService : ISearchForNzb @@ -80,11 +80,16 @@ public List EpisodeSearch(Episode episode) return SearchSingle(series, episode); } - public List SeasonSearch(int seriesId, int seasonNumber) + public List SeasonSearch(int seriesId, int seasonNumber, bool missingOnly) { var series = _seriesService.GetSeries(seriesId); var episodes = _episodeService.GetEpisodesBySeason(seriesId, seasonNumber); + if (missingOnly) + { + episodes = episodes.Where(e => e.Monitored && !e.HasFile).ToList(); + } + if (series.SeriesType == SeriesTypes.Anime) { return SearchAnimeSeason(series, episodes); @@ -217,10 +222,7 @@ private List SearchAnimeSeason(Series series, List ep foreach (var episode in episodes) { - if (episode.Monitored) - { - downloadDecisions.AddRange(SearchAnime(series, episode)); - } + downloadDecisions.AddRange(SearchAnime(series, episode)); } return downloadDecisions; diff --git a/src/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs b/src/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs index 677e71a9b..b8ec0f5cc 100644 --- a/src/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs @@ -22,7 +22,7 @@ public SeasonSearchService(ISearchForNzb nzbSearchService, public void Execute(SeasonSearchCommand message) { - var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, message.SeasonNumber); + var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, message.SeasonNumber, false); var processed = _processDownloadDecisions.ProcessDecisions(decisions); _logger.ProgressInfo("Season search completed. {0} reports downloaded.", processed.Grabbed.Count); diff --git a/src/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs b/src/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs index 7f336ebb6..fbaa3450f 100644 --- a/src/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs @@ -39,7 +39,7 @@ public void Execute(SeriesSearchCommand message) continue; } - var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, season.SeasonNumber); + var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, season.SeasonNumber, false); downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count; }