diff --git a/src/NzbDrone.Core.Test/TvTests/RefreshEpisodeServiceFixture.cs b/src/NzbDrone.Core.Test/TvTests/RefreshEpisodeServiceFixture.cs index 2cf1dad4c..592b56dc3 100644 --- a/src/NzbDrone.Core.Test/TvTests/RefreshEpisodeServiceFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/RefreshEpisodeServiceFixture.cs @@ -365,5 +365,33 @@ public void should_not_update_air_date_when_multiple_episodes_air_on_the_same_da _insertedEpisodes.Should().OnlyContain(e => e.AirDateUtc.Value.ToString("s") == episodes.First().AirDateUtc.Value.ToString("s")); } + + [Test] + public void should_prefer_regular_season_when_absolute_numbers_conflict() + { + var episodes = Builder.CreateListOfSize(2) + .Build() + .ToList(); + + episodes[0].AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber; + episodes[0].SeasonNumber = 0; + episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber); + + var existingEpisode = new Episode + { + SeasonNumber = episodes[0].SeasonNumber, + EpisodeNumber = episodes[0].EpisodeNumber, + AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber + }; + + Mocker.GetMock().Setup(c => c.GetEpisodeBySeries(It.IsAny())) + .Returns(new List { existingEpisode }); + + Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes); + + _updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber); + _updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber); + _updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Tv/RefreshEpisodeService.cs b/src/NzbDrone.Core/Tv/RefreshEpisodeService.cs index 8f64fed24..5882810f5 100644 --- a/src/NzbDrone.Core/Tv/RefreshEpisodeService.cs +++ b/src/NzbDrone.Core/Tv/RefreshEpisodeService.cs @@ -41,7 +41,7 @@ public void RefreshEpisodeInfo(Series series, IEnumerable remoteEpisode if (series.SeriesType == SeriesTypes.Anime) { - dupeFreeRemoteEpisodes = MapAbsoluteEpisodeNumbers(series, dupeFreeRemoteEpisodes); + dupeFreeRemoteEpisodes = MapAbsoluteEpisodeNumbers(dupeFreeRemoteEpisodes); } foreach (var episode in OrderEpisodes(series, dupeFreeRemoteEpisodes)) @@ -154,13 +154,14 @@ private void AdjustDirectToDvdAirDate(Series series, IEnumerable allEpi } } - private List MapAbsoluteEpisodeNumbers(Series series, List traktEpisodes) + private List MapAbsoluteEpisodeNumbers(List remoteEpisodes) { //Return all episodes with no abs number, but distinct for those with abs number - return traktEpisodes.Where(e => e.AbsoluteEpisodeNumber.HasValue) - .DistinctBy(e => e.AbsoluteEpisodeNumber.Value) - .Concat(traktEpisodes.Where(e => !e.AbsoluteEpisodeNumber.HasValue)) - .ToList(); + return remoteEpisodes.Where(e => e.AbsoluteEpisodeNumber.HasValue) + .OrderByDescending(e => e.SeasonNumber) + .DistinctBy(e => e.AbsoluteEpisodeNumber.Value) + .Concat(remoteEpisodes.Where(e => !e.AbsoluteEpisodeNumber.HasValue)) + .ToList(); } private Episode GetEpisodeToUpdate(Series series, Episode episode, List existingEpisodes)