diff --git a/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs b/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs index 120661418..5ef657a36 100644 --- a/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs @@ -207,6 +207,22 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeMonitoredServiceTests VerifyNotMonitored(e => e.HasFile); } + [Test] + public void should_not_monitor_latest_season_if_all_episodes_aired_more_than_90_days_ago() + { + _episodes.ForEach(e => e.AirDateUtc = DateTime.UtcNow.AddDays(-100)); + + var monitoringOptions = new MonitoringOptions + { + Monitor = MonitorTypes.LatestSeason + }; + + Subject.SetEpisodeMonitoredStatus(_series, monitoringOptions); + + Mocker.GetMock() + .Verify(v => v.UpdateEpisodes(It.Is>(l => l.All(e => !e.Monitored)))); + } + private void VerifyMonitored(Func predicate) { Mocker.GetMock() diff --git a/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs b/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs index f4ef80513..91f5eb560 100644 --- a/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs +++ b/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs @@ -77,7 +77,17 @@ namespace NzbDrone.Core.Tv break; case MonitorTypes.LatestSeason: + + if (episodes.Where(e => e.SeasonNumber == lastSeason) + .All(e => e.AirDateUtc.HasValue && !e.AirDateUtc.Value.InLastDays(90))) + { + _logger.Debug("[{0}] Unmonitoring all episodes because latest season aired more than 90 days ago", series.Title); + ToggleEpisodesMonitoredState(episodes, e => false); + break; + } + _logger.Debug("[{0}] Monitoring latest season episodes", series.Title); + ToggleEpisodesMonitoredState(episodes, e => e.SeasonNumber > 0 && e.SeasonNumber == lastSeason); break;