From 9fcb3a45738a2be2423a49d54cd626b0abca7196 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 4 Feb 2012 20:34:28 -0800 Subject: [PATCH] Improved: Episodes that are in the future AND have no title will not be added to db (place holder episodes in TVDB) --- .../ProviderTests/EpisodeProviderTest.cs | 143 ++++++++++++++++++ NzbDrone.Core/Providers/EpisodeProvider.cs | 5 + 2 files changed, 148 insertions(+) diff --git a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs index a476f8bfc..10d75fd55 100644 --- a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs @@ -255,6 +255,7 @@ namespace NzbDrone.Core.Test.ProviderTests actualCount.Should().Be(episodeCount); } + [Test] public void RefreshEpisodeInfo_should_set_older_than_1900_to_null() { @@ -369,6 +370,148 @@ namespace NzbDrone.Core.Test.ProviderTests result.Where(e => e.EpisodeNumber == 0 && e.SeasonNumber == 15).Single().Ignored.Should().BeTrue(); } + [Test] + public void RefreshEpisodeInfo_should_skip_future_episodes_with_no_title() + { + //Arrange + const int seriesId = 71663; + const int episodeCount = 10; + + var fakeEpisodes = Builder.CreateNew().With( + c => c.Episodes = new List(Builder.CreateListOfSize(episodeCount). + All() + .With(a => c.FirstAired = DateTime.Now.AddDays(-2)) + .With(e => e.EpisodeName = "Something") + .TheFirst(3) + .With(e => e.EpisodeName = "") + .With(e => e.FirstAired = DateTime.Now.AddDays(10)) + .Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + WithRealDb(); + + Db.Insert(fakeSeries); + + Mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + + //Act + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + result.Should().HaveCount(episodeCount - 3); + result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title) || c.AirDate < DateTime.Now); + } + + [Test] + public void RefreshEpisodeInfo_should_skip_older_than_1900_year_episodes_with_no_title() + { + //Arrange + const int seriesId = 71663; + const int episodeCount = 10; + + var fakeEpisodes = Builder.CreateNew().With( + c => c.Episodes = new List(Builder.CreateListOfSize(episodeCount). + All() + .With(a => c.FirstAired = DateTime.Now.AddDays(-2)) + .With(e => e.EpisodeName = "Something") + .TheFirst(3) + .With(e => e.EpisodeName = "") + .With(e => e.FirstAired = new DateTime(1889,1,1)) + .Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + WithRealDb(); + + Db.Insert(fakeSeries); + + Mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + + //Act + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + result.Should().HaveCount(episodeCount - 3); + result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title) || c.AirDate < DateTime.Now); + } + + [Test] + public void RefreshEpisodeInfo_should_add_future_episodes_with_title() + { + const int seriesId = 71663; + + var fakeEpisodes = Builder.CreateNew().With( + c => c.Episodes = new List(Builder.CreateListOfSize(10). + All() + .With(a => a.FirstAired = DateTime.Now.AddDays(10)) + .With(e => e.EpisodeName = "Something") + .Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + WithRealDb(); + + Db.Insert(fakeSeries); + + Mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + + //Act + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + result.Should().HaveSameCount(fakeEpisodes.Episodes); + } + + [Test] + public void RefreshEpisodeInfo_should_add_old_episodes_with_no_title() + { + const int seriesId = 71663; + + + var fakeEpisodes = Builder.CreateNew().With( + c => c.Episodes = new List(Builder.CreateListOfSize(10). + All() + .With(a => a.FirstAired = DateTime.Now.AddDays(-10)) + .With(e => e.EpisodeName = string.Empty) + .Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + WithRealDb(); + + Db.Insert(fakeSeries); + + Mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + + //Act + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + result.Should().HaveSameCount(fakeEpisodes.Episodes); + } + + [Test] public void RefreshEpisodeInfo_ignore_season_zero() { diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 67903794e..77760810f 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -282,6 +282,11 @@ namespace NzbDrone.Core.Providers { try { + //skip episodes that are too far in the future and have no title. + if ((episode.FirstAired > DateTime.Now.AddDays(2) || episode.FirstAired.Year < 1900) && + string.IsNullOrWhiteSpace(episode.EpisodeName)) + continue; + Logger.Trace("Updating info for [{0}] - S{1}E{2}", tvDbSeriesInfo.SeriesName, episode.SeasonNumber, episode.EpisodeNumber); //first check using tvdbId, this should cover cases when and episode number in a season is changed