diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/PrioritizeDownloadDecisionFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/PrioritizeDownloadDecisionFixture.cs index 148169d9c..76e139fe1 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/PrioritizeDownloadDecisionFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/PrioritizeDownloadDecisionFixture.cs @@ -217,6 +217,37 @@ namespace NzbDrone.Core.Test.DecisionEngineTests qualifiedReports.First().RemoteEpisode.ParsedEpisodeInfo.FullSeason.Should().BeTrue(); } + [Test] + public void should_prefer_multiepisode_over_single_episode_for_anime() + { + var remoteEpisode1 = GivenRemoteEpisode(new List { GivenEpisode(1), GivenEpisode(2) }, new QualityModel(Quality.HDTV720p)); + var remoteEpisode2 = GivenRemoteEpisode(new List { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p)); + + remoteEpisode1.Series.SeriesType = SeriesTypes.Anime; + remoteEpisode2.Series.SeriesType = SeriesTypes.Anime; + + var decisions = new List(); + decisions.Add(new DownloadDecision(remoteEpisode1)); + decisions.Add(new DownloadDecision(remoteEpisode2)); + + var qualifiedReports = Subject.PrioritizeDecisions(decisions); + qualifiedReports.First().RemoteEpisode.Episodes.Count.Should().Be(remoteEpisode1.Episodes.Count); + } + + [Test] + public void should_prefer_single_episode_over_multi_episode_for_non_anime() + { + var remoteEpisode1 = GivenRemoteEpisode(new List { GivenEpisode(1), GivenEpisode(2) }, new QualityModel(Quality.HDTV720p)); + var remoteEpisode2 = GivenRemoteEpisode(new List { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p)); + + var decisions = new List(); + decisions.Add(new DownloadDecision(remoteEpisode1)); + decisions.Add(new DownloadDecision(remoteEpisode2)); + + var qualifiedReports = Subject.PrioritizeDecisions(decisions); + qualifiedReports.First().RemoteEpisode.Episodes.Count.Should().Be(remoteEpisode2.Episodes.Count); + } + [Test] public void should_prefer_releases_with_more_seeders() { diff --git a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionComparer.cs b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionComparer.cs index 882105a9d..a85410046 100644 --- a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionComparer.cs +++ b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionComparer.cs @@ -4,6 +4,7 @@ using System.Linq; using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Profiles.Delay; +using NzbDrone.Core.Tv; namespace NzbDrone.Core.DecisionEngine { @@ -75,8 +76,21 @@ namespace NzbDrone.Core.DecisionEngine private int CompareEpisodeCount(DownloadDecision x, DownloadDecision y) { - return CompareAll(CompareBy(x.RemoteEpisode, y.RemoteEpisode, remoteEpisode => remoteEpisode.ParsedEpisodeInfo.FullSeason), - CompareByReverse(x.RemoteEpisode, y.RemoteEpisode, remoteEpisode => remoteEpisode.Episodes.Count)); + var seasonPackCompare = CompareBy(x.RemoteEpisode, y.RemoteEpisode, + remoteEpisode => remoteEpisode.ParsedEpisodeInfo.FullSeason); + + if (seasonPackCompare != 0) + { + return seasonPackCompare; + } + + if (x.RemoteEpisode.Series.SeriesType == SeriesTypes.Anime & + y.RemoteEpisode.Series.SeriesType == SeriesTypes.Anime) + { + return CompareBy(x.RemoteEpisode, y.RemoteEpisode, remoteEpisode => remoteEpisode.Episodes.Count); + } + + return CompareByReverse(x.RemoteEpisode, y.RemoteEpisode, remoteEpisode => remoteEpisode.Episodes.Count); } private int CompareEpisodeNumber(DownloadDecision x, DownloadDecision y)