From d22905676c5b56df5ca72f8fb656694229f3252c Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 28 May 2011 18:58:35 -0700 Subject: [PATCH] Fixed American Dad's scene naming gong show --- NzbDrone.Core.Test/TvDbProviderTest.cs | 72 ++++++++++++++++++++----- NzbDrone.Core/Providers/TvDbProvider.cs | 28 +++++++++- 2 files changed, 86 insertions(+), 14 deletions(-) diff --git a/NzbDrone.Core.Test/TvDbProviderTest.cs b/NzbDrone.Core.Test/TvDbProviderTest.cs index 992f991be..2d89d21e5 100644 --- a/NzbDrone.Core.Test/TvDbProviderTest.cs +++ b/NzbDrone.Core.Test/TvDbProviderTest.cs @@ -1,5 +1,6 @@ // ReSharper disable RedundantUsingDirective using System; +using System.Linq; using MbUnit.Framework; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; @@ -38,19 +39,19 @@ namespace NzbDrone.Core.Test [Test] - [Row(new object[] {"CAPITAL", "capital", true})] - [Row(new object[] {"Something!!", "Something", true})] - [Row(new object[] {"Simpsons 2000", "Simpsons", true})] - [Row(new object[] {"Simp222sons", "Simpsons", true})] - [Row(new object[] {"Simpsons", "The Simpsons", true})] - [Row(new object[] {"Law and order", "Law & order", true})] - [Row(new object[] {"xxAndxx", "xxxx", false})] - [Row(new object[] {"Andxx", "xx", false})] - [Row(new object[] {"xxAnd", "xx", false})] - [Row(new object[] {"Thexx", "xx", false})] - [Row(new object[] {"Thexx", "xx", false})] - [Row(new object[] {"xxThexx", "xxxxx", false})] - [Row(new object[] {"Simpsons The", "Simpsons", true})] + [Row(new object[] { "CAPITAL", "capital", true })] + [Row(new object[] { "Something!!", "Something", true })] + [Row(new object[] { "Simpsons 2000", "Simpsons", true })] + [Row(new object[] { "Simp222sons", "Simpsons", true })] + [Row(new object[] { "Simpsons", "The Simpsons", true })] + [Row(new object[] { "Law and order", "Law & order", true })] + [Row(new object[] { "xxAndxx", "xxxx", false })] + [Row(new object[] { "Andxx", "xx", false })] + [Row(new object[] { "xxAnd", "xx", false })] + [Row(new object[] { "Thexx", "xx", false })] + [Row(new object[] { "Thexx", "xx", false })] + [Row(new object[] { "xxThexx", "xxxxx", false })] + [Row(new object[] { "Simpsons The", "Simpsons", true })] public void Name_match_test(string a, string b, bool match) { bool result = TvDbProvider.IsTitleMatch(a, b); @@ -83,5 +84,50 @@ namespace NzbDrone.Core.Test //assert Assert.IsNull(result); } + + + [Test] + public void American_dad_fix() + { + //setup + var tvdbProvider = new TvDbProvider(); + + //act + var result = tvdbProvider.GetSeries(73141, true); + + var seasons = result.Episodes.Select(e => e.SeasonNumber) + .Distinct().ToList(); + + + + var seasons1 = result.Episodes.Where(e => e.SeasonNumber == 1).ToList(); + var seasons2 = result.Episodes.Where(e => e.SeasonNumber == 2).ToList(); + var seasons3 = result.Episodes.Where(e => e.SeasonNumber == 3).ToList(); + var seasons4 = result.Episodes.Where(e => e.SeasonNumber == 4).ToList(); + var seasons5 = result.Episodes.Where(e => e.SeasonNumber == 5).ToList(); + var seasons6 = result.Episodes.Where(e => e.SeasonNumber == 6).ToList(); + + + foreach (var episode in result.Episodes) + { + Console.WriteLine(episode); + } + + //assert + Assert.Count(7, seasons); + Assert.Count(23, seasons1); + Assert.Count(19, seasons2); + Assert.Count(16, seasons3); + Assert.Count(20, seasons4); + Assert.Count(18, seasons5); + + Assert.Distinct(seasons1.Select(s => s.EpisodeNumber)); + Assert.Distinct(seasons2.Select(s => s.EpisodeNumber)); + Assert.Distinct(seasons3.Select(s => s.EpisodeNumber)); + Assert.Distinct(seasons4.Select(s => s.EpisodeNumber)); + Assert.Distinct(seasons5.Select(s => s.EpisodeNumber)); + Assert.Distinct(seasons6.Select(s => s.EpisodeNumber)); + + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/TvDbProvider.cs b/NzbDrone.Core/Providers/TvDbProvider.cs index ad3340129..7916f3b02 100644 --- a/NzbDrone.Core/Providers/TvDbProvider.cs +++ b/NzbDrone.Core/Providers/TvDbProvider.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using NLog; @@ -79,7 +80,32 @@ namespace NzbDrone.Core.Providers lock (_handler) { Logger.Debug("Fetching SeriesId'{0}' from tvdb", id); - return _handler.GetSeries(id, TvdbLanguage.DefaultLanguage, loadEpisodes, false, false); + var result = _handler.GetSeries(id, TvdbLanguage.DefaultLanguage, loadEpisodes, false, false); + + + //Fix American Dad's scene gongshow + if (result != null && result.Id == 73141) + { + var seasonOneEpisodeCount = result.Episodes.Where(e => e.SeasonNumber == 0).Count(); + var seasonOneId = result.Episodes.Where(e => e.SeasonNumber == 1).First().SeasonId; + + foreach (var episode in result.Episodes) + { + if (episode.SeasonNumber > 1) + { + if (episode.SeasonNumber == 2) + { + episode.EpisodeNumber = episode.EpisodeNumber + seasonOneEpisodeCount; + episode.SeasonId = seasonOneId; + } + + episode.SeasonNumber = episode.SeasonNumber - 1; + } + + } + } + + return result; } }