From 7560a70dd41754745e7fbff7a35be466d33ff704 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 19 Jun 2011 10:56:54 -0700 Subject: [PATCH] fixed duplicated episodes coming in from Tvdb --- NzbDrone.Core.Test/TvDbProviderTest.cs | 15 +++++++++++++++ NzbDrone.Core/Providers/TvDbProvider.cs | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/NzbDrone.Core.Test/TvDbProviderTest.cs b/NzbDrone.Core.Test/TvDbProviderTest.cs index 4930a5bba..f196ca64b 100644 --- a/NzbDrone.Core.Test/TvDbProviderTest.cs +++ b/NzbDrone.Core.Test/TvDbProviderTest.cs @@ -84,6 +84,21 @@ namespace NzbDrone.Core.Test Assert.IsNull(result); } + [Test] + public void none_unique_season_episode_number() + { + //setup + var tvdbProvider = new TvDbProvider(); + + //act + var result = tvdbProvider.GetSeries(75978, true);//Family guy + + //Asserts that when episodes are grouped by Season/Episode each group contains maximum of + //one item. + result.Episodes.GroupBy(e => e.SeasonNumber.ToString("000") + e.EpisodeNumber.ToString("000")) + .Max(e => e.Count()).Should().Be(1); + + } [Test] public void American_dad_fix() diff --git a/NzbDrone.Core/Providers/TvDbProvider.cs b/NzbDrone.Core/Providers/TvDbProvider.cs index ccfa19edf..7b3a91ac1 100644 --- a/NzbDrone.Core/Providers/TvDbProvider.cs +++ b/NzbDrone.Core/Providers/TvDbProvider.cs @@ -105,6 +105,13 @@ namespace NzbDrone.Core.Providers } } + //Remove duplicated episodes + var episodes = result.Episodes.OrderByDescending(e => e.FirstAired).ThenByDescending(e => e.EpisodeName) + .GroupBy(e => e.SeriesId.ToString("000000") + e.SeasonNumber.ToString("000") + e.EpisodeNumber.ToString("000")) + .Select(e => e.First()); + + result.Episodes = episodes.ToList(); + return result; } }