diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs index 117c81ec0..5515fcedf 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs @@ -48,7 +48,7 @@ public void Setup() Series = series, Release = new ReleaseInfo(), ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) }, - Episodes = new List { new Episode() } + Episodes = new List { new Episode() { Id = 2 } } }; @@ -59,13 +59,21 @@ public void Setup() .Build(); Mocker.GetMock().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType); + + Mocker.GetMock().Setup( + s => s.GetEpisodesBySeason(It.IsAny(), It.IsAny())) + .Returns(new List() { + new Episode(), new Episode(), new Episode(), new Episode(), new Episode(), + new Episode(), new Episode(), new Episode(), new Episode() { Id = 2 }, new Episode() }); } private void GivenLastEpisode() { Mocker.GetMock().Setup( - s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny())) - .Returns(true); + s => s.GetEpisodesBySeason(It.IsAny(), It.IsAny())) + .Returns(new List() { + new Episode(), new Episode(), new Episode(), new Episode(), new Episode(), + new Episode(), new Episode(), new Episode(), new Episode(), new Episode() { Id = 2 } }); } [TestCase(30, 50, false)] @@ -110,10 +118,6 @@ public void multi_episode(int runtime, int sizeInMegaBytes, bool expectedResult) parseResultMulti.Series = series; parseResultMulti.Release.Size = sizeInMegaBytes.Megabytes(); - Mocker.GetMock().Setup( - s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny())) - .Returns(false); - Subject.IsSatisfiedBy(parseResultMulti, null).Should().Be(expectedResult); } @@ -129,10 +133,6 @@ public void multiset_episode(int runtime, int sizeInMegaBytes, bool expectedResu parseResultMultiSet.Series = series; parseResultMultiSet.Release.Size = sizeInMegaBytes.Megabytes(); - Mocker.GetMock().Setup( - s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny())) - .Returns(false); - Subject.IsSatisfiedBy(parseResultMultiSet, null).Should().Be(expectedResult); } diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs index 5073ca546..1d776f3e1 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs @@ -4,6 +4,7 @@ using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; +using System.Collections.Generic; namespace NzbDrone.Core.DecisionEngine.Specifications { @@ -66,10 +67,27 @@ public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase sear //Multiply maxSize by Series.Runtime maxSize = maxSize * subject.Series.Runtime * subject.Episodes.Count; - //Check if there was only one episode parsed and it is the first - if (subject.Episodes.Count == 1 && _episodeService.IsFirstOrLastEpisodeOfSeason(subject.Episodes.First().Id)) + if (subject.Episodes.Count == 1) { - maxSize = maxSize * 2; + Episode episode = subject.Episodes.First(); + List seasonEpisodes; + + var seasonSearchCriteria = searchCriteria as SeasonSearchCriteria; + if (seasonSearchCriteria != null && !seasonSearchCriteria.Series.UseSceneNumbering && seasonSearchCriteria.Episodes.Any(v => v.Id == episode.Id)) + { + seasonEpisodes = (searchCriteria as SeasonSearchCriteria).Episodes; + } + else + { + seasonEpisodes = _episodeService.GetEpisodesBySeason(episode.SeriesId, episode.SeasonNumber); + } + + //Ensure that this is either the first episode + //or is the last episode in a season that has 10 or more episodes + if (seasonEpisodes.First().Id == episode.Id || (seasonEpisodes.Count() >= 10 && seasonEpisodes.Last().Id == episode.Id)) + { + maxSize = maxSize * 2; + } } //If the parsed size is greater than maxSize we don't want it diff --git a/src/NzbDrone.Core/Tv/EpisodeService.cs b/src/NzbDrone.Core/Tv/EpisodeService.cs index 402642e0a..09c073e56 100644 --- a/src/NzbDrone.Core/Tv/EpisodeService.cs +++ b/src/NzbDrone.Core/Tv/EpisodeService.cs @@ -27,7 +27,6 @@ public interface IEpisodeService List GetEpisodesByFileId(int episodeFileId); void UpdateEpisode(Episode episode); void SetEpisodeMonitored(int episodeId, bool monitored); - bool IsFirstOrLastEpisodeOfSeason(int episodeId); void UpdateEpisodes(List episodes); List EpisodesBetweenDates(DateTime start, DateTime end); void InsertMany(List episodes); @@ -141,19 +140,6 @@ public void SetEpisodeMonitoredBySeason(int seriesId, int seasonNumber, bool mon _episodeRepository.SetMonitoredBySeason(seriesId, seasonNumber, monitored); } - public bool IsFirstOrLastEpisodeOfSeason(int episodeId) - { - var episode = GetEpisode(episodeId); - var seasonEpisodes = GetEpisodesBySeason(episode.SeriesId, episode.SeasonNumber); - - //Ensure that this is either the first episode - //or is the last episode in a season that has 10 or more episodes - if (seasonEpisodes.First().EpisodeNumber == episode.EpisodeNumber || (seasonEpisodes.Count() >= 10 && seasonEpisodes.Last().EpisodeNumber == episode.EpisodeNumber)) - return true; - - return false; - } - public void UpdateEpisodes(List episodes) { _episodeRepository.UpdateMany(episodes);