From d09a82a20f3de5c1ebbfdd2e1c02a7362b3ef374 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 2 Jun 2011 18:15:02 -0700 Subject: [PATCH] Integrated scene name helper into episode search, series lookup --- NzbDrone.Core.Test/EpisodeSearchJobTest.cs | 49 ++ NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + NzbDrone.Core.Test/SceneNameHelperTest.cs | 32 ++ NzbDrone.Core.Test/TvDbProviderTest.cs | 5 +- NzbDrone.Core/Helpers/SceneNameHelper.cs | 429 ++++++------------ .../Providers/Jobs/EpisodeSearchJob.cs | 15 +- NzbDrone.Core/Providers/SeriesProvider.cs | 4 +- 7 files changed, 228 insertions(+), 307 deletions(-) create mode 100644 NzbDrone.Core.Test/SceneNameHelperTest.cs diff --git a/NzbDrone.Core.Test/EpisodeSearchJobTest.cs b/NzbDrone.Core.Test/EpisodeSearchJobTest.cs index 5146f6499..4c69d505c 100644 --- a/NzbDrone.Core.Test/EpisodeSearchJobTest.cs +++ b/NzbDrone.Core.Test/EpisodeSearchJobTest.cs @@ -228,6 +228,7 @@ namespace NzbDrone.Core.Test .Setup(c => c.GetEpisode(episode.EpisodeId)) .Returns(episode); + var indexer1 = new Mock(); indexer1.Setup(c => c.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber)) .Returns(parseResults).Verifiable(); @@ -259,6 +260,54 @@ namespace NzbDrone.Core.Test indexer2.VerifyAll(); } + [Test] + public void start_should_use_scene_name_to_search() + { + var parseResults = Builder.CreateListOfSize(4) + .Build(); + + var episode = Builder.CreateNew() + .With(c => c.Series = Builder.CreateNew().With(s => s.SeriesId = 71256).Build()) + .With(c => c.SeasonNumber = 12) + .Build(); + + var mocker = new AutoMoqer(MockBehavior.Strict); + + mocker.GetMock() + .Setup(c => c.GetEpisode(episode.EpisodeId)) + .Returns(episode); + + var indexer1 = new Mock(); + indexer1.Setup(c => c.FetchEpisode("The Daily Show", episode.SeasonNumber, episode.EpisodeNumber)) + .Returns(parseResults).Verifiable(); + + + var indexer2 = new Mock(); + indexer2.Setup(c => c.FetchEpisode("The Daily Show", episode.SeasonNumber, episode.EpisodeNumber)) + .Returns(parseResults).Verifiable(); + + var indexers = new List { indexer1.Object, indexer2.Object }; + + mocker.GetMock() + .Setup(c => c.GetEnabledIndexers()) + .Returns(indexers); + + mocker.GetMock() + .Setup(c => c.IsQualityNeeded(It.Is(d => d.Series != null && d.Episodes.Count != 0))).Returns(false); + + //Act + mocker.Resolve().Start(new ProgressNotification("Test"), episode.EpisodeId); + + + //Assert + mocker.VerifyAllMocks(); + mocker.GetMock().Verify(c => c.IsQualityNeeded(It.IsAny()), + Times.Exactly(8)); + ExceptionVerification.ExcpectedWarns(1); + indexer1.VerifyAll(); + indexer2.VerifyAll(); + } + [Test] public void start_failed_indexer_should_not_break_job() diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index a05264c86..3faf3c3f3 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -125,6 +125,7 @@ + diff --git a/NzbDrone.Core.Test/SceneNameHelperTest.cs b/NzbDrone.Core.Test/SceneNameHelperTest.cs new file mode 100644 index 000000000..91feadcb0 --- /dev/null +++ b/NzbDrone.Core.Test/SceneNameHelperTest.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Helpers; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class SceneNameHelperTest : TestBase + { + + [Test] + public void GetIdByName_exists() + { + var id = SceneNameHelper.GetIdByName("CSI New York"); + id.Should().Be(73696); + } + + + [Test] + public void GetTitleById_exists() + { + var title = SceneNameHelper.GetTitleById(71256); + title.Should().Be("The Daily Show"); + } + } +} diff --git a/NzbDrone.Core.Test/TvDbProviderTest.cs b/NzbDrone.Core.Test/TvDbProviderTest.cs index 20cf5916f..be085c294 100644 --- a/NzbDrone.Core.Test/TvDbProviderTest.cs +++ b/NzbDrone.Core.Test/TvDbProviderTest.cs @@ -16,12 +16,9 @@ namespace NzbDrone.Core.Test [TestCase("The Simpsons")] [TestCase("Family Guy")] [TestCase("South Park")] - [TestCase("clone high, usa")] public void successful_search(string title) { - var tvCont = new TvDbProvider(); - var result = tvCont.SearchSeries(title); - + var result = new TvDbProvider().SearchSeries(title); result.Should().NotBeEmpty(); result[0].SeriesName.Should().Be(title); diff --git a/NzbDrone.Core/Helpers/SceneNameHelper.cs b/NzbDrone.Core/Helpers/SceneNameHelper.cs index d514fafe2..1342bc591 100644 --- a/NzbDrone.Core/Helpers/SceneNameHelper.cs +++ b/NzbDrone.Core/Helpers/SceneNameHelper.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using NzbDrone.Core.Model; namespace NzbDrone.Core.Helpers { @@ -9,307 +7,140 @@ namespace NzbDrone.Core.Helpers { //Todo: Move this to a publically available location (so updates can be applied without releasing a new version of NzbDrone) //Todo: GoogleDocs? WCF Web Services on NzbDrone.com? - private static readonly List SceneNameMappings = new List - { - new SceneNameModel - {SeriesId = 72546, Name = "CSI"}, - new SceneNameModel - { - SeriesId = 73696, - Name = "CSI New York" - }, - new SceneNameModel - {SeriesId = 73696, Name = "CSI NY"}, - new SceneNameModel - { - SeriesId = 110381, - Name = "Archer" - }, - new SceneNameModel - { - SeriesId = 83897, - Name = - "Life After People The Series" - }, - new SceneNameModel - { - SeriesId = 83897, - Name = "Life After People" - }, - new SceneNameModel - { - SeriesId = 80552, - Name = "Kitchen Nightmares US" - }, - new SceneNameModel - { - SeriesId = 71256, - Name = "The Daily Show" - }, - new SceneNameModel - { - SeriesId = 71256, - Name = - "The Daily Show with Jon Stewart" - }, - new SceneNameModel - { - SeriesId = 75692, - Name = "Law and Order SVU" - }, - new SceneNameModel - { - SeriesId = 75692, - Name = - "Law and Order Special Victims Unit" - }, - new SceneNameModel - { - SeriesId = 71489, - Name = - "Law and Order Criminal Intent" - }, - new SceneNameModel - { - SeriesId = 71489, - Name = "Law and Order CI" - }, - new SceneNameModel - { - SeriesId = 79590, - Name = "Dancing With The Stars US" - }, - new SceneNameModel - { - SeriesId = 73387, - Name = "Craig Ferguson" - }, - new SceneNameModel - { - SeriesId = 85355, - Name = "Jimmy Fallon" - }, - new SceneNameModel - { - SeriesId = 75088, - Name = "David Letterman" - }, - new SceneNameModel - { - SeriesId = 76706, - Name = "Big Brother US" - }, - new SceneNameModel - { - SeriesId = 105521, - Name = "The Colony" - }, - new SceneNameModel - { - SeriesId = 105521, - Name = "The Colony US" - }, - new SceneNameModel - { - SeriesId = 76235, - Name = - "Americas Funniest Home Videos" - }, - new SceneNameModel - {SeriesId = 76235, Name = "AFHV"}, - new SceneNameModel - { - SeriesId = 139941, - Name = "Childrens Hospital US" - }, - new SceneNameModel - { - SeriesId = 139941, - Name = "Childrens Hospital" - }, - new SceneNameModel - {SeriesId = 83123, Name = "Merlin"}, - new SceneNameModel - { - SeriesId = 83123, - Name = "Merlin 2008" - }, - new SceneNameModel - { - SeriesId = 76779, - Name = "WWE Monday Night RAW" - }, - new SceneNameModel - { - SeriesId = 164951, - Name = "Shit My Dad Says" - }, - new SceneNameModel - { - SeriesId = 83714, - Name = "Genius with Dave Gorman" - }, - new SceneNameModel - { - SeriesId = 168161, - Name = "Law and Order LA" - }, - new SceneNameModel - { - SeriesId = 77526, - Name = "Star Trek TOS" - }, - new SceneNameModel - { - SeriesId = 72073, - Name = "Star Trek DS9" - }, - new SceneNameModel - { - SeriesId = 72194, - Name = "Ellen Degeneres" - }, - new SceneNameModel - { - SeriesId = 72194, - Name = "Ellen Degeneres" - }, - new SceneNameModel - { - SeriesId = 195831, - Name = "Drinking Made Easy" - }, - new SceneNameModel - { - SeriesId = 195831, - Name = - "Zane Lampreys Drinking Made Easy" - }, - new SceneNameModel - {SeriesId = 76133, Name = "Poirot"}, - new SceneNameModel - { - SeriesId = 76133, - Name = "Agatha Christies Poirot" - }, - new SceneNameModel - { - SeriesId = 70870, - Name = - "The Real World Road Rules Challenge" - }, - new SceneNameModel - { - SeriesId = 70870, - Name = "The Challenge Cutthroat" - }, - new SceneNameModel - { - SeriesId = 77444, - Name = "This Old House Program" - }, - new SceneNameModel - { - SeriesId = 73290, - Name = "60 Minutes US" - }, - new SceneNameModel - {SeriesId = 194751, Name = "Conan"}, - new SceneNameModel - { - SeriesId = 194751, - Name = "Conan 2010" - }, - new SceneNameModel - { - SeriesId = 164451, - Name = "Carlos 2010" - }, - new SceneNameModel - { - SeriesId = 70726, - Name = "Babalon 5" - }, - new SceneNameModel - { - SeriesId = 70726, - Name = "Babalon5" - }, - new SceneNameModel - {SeriesId = 83714, Name = "Genius"}, - new SceneNameModel - { - SeriesId = 83714, - Name = "Genius With Dave Gormand" - }, - new SceneNameModel - { - SeriesId = 212571, - Name = "Come Fly With Me 2010" - }, - new SceneNameModel - { - SeriesId = 81563, - Name = "Border Security" - }, - new SceneNameModel - { - SeriesId = 81563, - Name = - "Border Security Australias Frontline" - }, - new SceneNameModel - { - SeriesId = 172381, - Name = "Silent Library US" - }, - new SceneNameModel - { - SeriesId = 131791, - Name = "Sci-Fi Science" - }, - new SceneNameModel - { - SeriesId = 80646, - Name = "Frontline" - }, - new SceneNameModel - { - SeriesId = 80646, - Name = "Frontline US" - }, - new SceneNameModel - { - SeriesId = 189931, - Name = "RBT AU" - }, - new SceneNameModel - {SeriesId = 73255, Name = "House"}, - new SceneNameModel - { - SeriesId = 73255, - Name = "House MD" - }, - new SceneNameModel - { - SeriesId = 73244, - Name = "The Office" - }, - new SceneNameModel - { - SeriesId = 73244, - Name = "The Office US" - }, - }; + private static readonly Dictionary SeriesIdLookupList = new Dictionary(); + private static readonly Dictionary SceneNameLookupList = new Dictionary(); - public static int FindByName(string cleanSeriesName) + + static SceneNameHelper() + { + //These values are used to match report titles parsed out of RSS to a series in the DB + SeriesIdLookupList.Add(Parser.NormalizeTitle("CSI"), 72546); + SeriesIdLookupList.Add(Parser.NormalizeTitle("CSI New York"), 73696); + SeriesIdLookupList.Add(Parser.NormalizeTitle("CSI NY"), 73696); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Archer"), 110381); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Life After People The Series"), 83897); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Life After People"), 83897); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Kitchen Nightmares US"), 80552); + SeriesIdLookupList.Add(Parser.NormalizeTitle("The Daily Show"), 71256); + SeriesIdLookupList.Add(Parser.NormalizeTitle("The Daily Show with Jon Stewart"), 71256); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Law and Order SVU"), 75692); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Law and Order Special Victims Unit"), 75692); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Law and Order Criminal Intent"), 71489); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Law and Order CI"), 71489); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Dancing With The Stars US"), 79590); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Craig Ferguson"), 73387); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Jimmy Fallon"), 85355); + SeriesIdLookupList.Add(Parser.NormalizeTitle("David Letterman"), 75088); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Big Brother US"), 76706); + SeriesIdLookupList.Add(Parser.NormalizeTitle("The Colony"), 105521); + SeriesIdLookupList.Add(Parser.NormalizeTitle("The Colony US"), 105521); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Americas Funniest Home Videos"), 76235); + SeriesIdLookupList.Add(Parser.NormalizeTitle("AFHV"), 76235); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Childrens Hospital US"), 139941); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Childrens Hospital"), 139941); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Merlin"), 83123); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Merlin 2008"), 83123); + SeriesIdLookupList.Add(Parser.NormalizeTitle("WWE Monday Night RAW"), 76779); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Shit My Dad Says"), 164951); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Genius with Dave Gorman"), 83714); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Law and Order LA"), 168161); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Star Trek TOS"), 77526); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Star Trek DS9"), 72073); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Ellen Degeneres"), 72194); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Drinking Made Easy"), 195831); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Zane Lampreys Drinking Made Easy"), 195831); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Poirot"), 76133); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Agatha Christies Poirot"), 76133); + SeriesIdLookupList.Add(Parser.NormalizeTitle("The Real World Road Rules Challenge"), 70870); + SeriesIdLookupList.Add(Parser.NormalizeTitle("The Challenge Cutthroat"), 70870); + SeriesIdLookupList.Add(Parser.NormalizeTitle("This Old House Program"), 77444); + SeriesIdLookupList.Add(Parser.NormalizeTitle("60 Minutes US"), 73290); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Conan"), 194751); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Conan 2010"), 194751); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Carlos 2010"), 164451); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Babalon 5"), 70726); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Babalon5"), 70726); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Genius"), 83714); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Genius With Dave Gormand"), 83714); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Come Fly With Me 2010"), 212571); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Border Security"), 81563); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Border Security Australias Frontline"), 81563); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Silent Library US"), 172381); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Sci-Fi Science"), 131791); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Frontline"), 80646); + SeriesIdLookupList.Add(Parser.NormalizeTitle("Frontline US"), 80646); + SeriesIdLookupList.Add(Parser.NormalizeTitle("RBT AU"), 189931); + SeriesIdLookupList.Add(Parser.NormalizeTitle("House"), 73255); + SeriesIdLookupList.Add(Parser.NormalizeTitle("House MD"), 73255); + SeriesIdLookupList.Add(Parser.NormalizeTitle("The Office"), 73244); + SeriesIdLookupList.Add(Parser.NormalizeTitle("The Office US"), 73244); + + //These values are used when doing an indexer search. + SceneNameLookupList.Add(72546, "CSI"); //CSI + SceneNameLookupList.Add(73696, "CSI"); //CSI NY + SceneNameLookupList.Add(110381, "Archer"); + SceneNameLookupList.Add(83897, "Life After People"); + SceneNameLookupList.Add(80552, "Kitchen Nightmares US"); + SceneNameLookupList.Add(71256, "The Daily Show"); //The Daily Show with Jon Stewart + SceneNameLookupList.Add(75692, "Law and Order"); //SVU + SceneNameLookupList.Add(71489, "Law and Order");//CI + SceneNameLookupList.Add(79590, "Dancing With The Stars US"); + SceneNameLookupList.Add(73387, "Craig Ferguson"); + SceneNameLookupList.Add(85355, "Jimmy Fallon"); + SceneNameLookupList.Add(75088, "David Letterman"); + SceneNameLookupList.Add(76706, "Big Brother US"); + SceneNameLookupList.Add(105521, "The Colony"); + SceneNameLookupList.Add(76235, "Americas Funniest Home Videos"); + SceneNameLookupList.Add(139941, "Childrens Hospital"); + SceneNameLookupList.Add(83123, "Merlin"); + SceneNameLookupList.Add(76779, "WWE Monday Night RAW"); + SceneNameLookupList.Add(164951, "Shit My Dad Says"); + SceneNameLookupList.Add(168161, "Law and Order LA"); + SceneNameLookupList.Add(77526, "Star Trek TOS"); + SceneNameLookupList.Add(72073, "Star Trek DS9"); + SceneNameLookupList.Add(72194, "Ellen Degeneres"); + SceneNameLookupList.Add(195831, "Drinking Made Easy");//Zane Lampreys Drinking Made Easy + SceneNameLookupList.Add(76133, "Poirot"); //Agatha Christies Poirot + SceneNameLookupList.Add(70870, "The Real World Road Rules Challenge"); + SceneNameLookupList.Add(77444, "This Old House Program"); + SceneNameLookupList.Add(73290, "60 Minutes US"); + SceneNameLookupList.Add(194751, "Conan"); + SceneNameLookupList.Add(164451, "Carlos 2010"); + SceneNameLookupList.Add(70726, "Babalon"); //5 + SceneNameLookupList.Add(83714, "Genius"); //Genius With Dave Gormand + SceneNameLookupList.Add(212571, "Come Fly With Me 2010"); + SceneNameLookupList.Add(81563, "Border Security"); + SceneNameLookupList.Add(172381, "Silent Library US"); + SceneNameLookupList.Add(131791, "Sci-Fi Science"); + SceneNameLookupList.Add(80646, "Frontline"); + SceneNameLookupList.Add(189931, "RBT AU"); + SceneNameLookupList.Add(73255, "House"); + SceneNameLookupList.Add(73244, "The Office"); + } + + + public static Nullable GetIdByName(string cleanSeriesName) + { + int id; + + if (SeriesIdLookupList.TryGetValue(Parser.NormalizeTitle(cleanSeriesName), out id)) + { + return id; + } + + return null; + } + + public static String GetTitleById(int seriesId) { - var map = SceneNameMappings.Find(s => Parser.NormalizeTitle(s.Name) == cleanSeriesName); + string title; - if (map == null) - return 0; + if (SceneNameLookupList.TryGetValue(seriesId, out title)) + { + return title; + } - return map.SeriesId; + return null; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Jobs/EpisodeSearchJob.cs b/NzbDrone.Core/Providers/Jobs/EpisodeSearchJob.cs index cb80525aa..bbb151fa5 100644 --- a/NzbDrone.Core/Providers/Jobs/EpisodeSearchJob.cs +++ b/NzbDrone.Core/Providers/Jobs/EpisodeSearchJob.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers.Indexer; @@ -43,15 +44,25 @@ namespace NzbDrone.Core.Providers.Jobs throw new ArgumentOutOfRangeException("targetId"); var episode = _episodeProvider.GetEpisode(targetId); + if (episode == null) { Logger.Error("Unable to find an episode {0} in database", targetId); return; } + var series = episode.Series; + var indexers = _indexerProvider.GetEnabledIndexers(); var reports = new List(); + var title = SceneNameHelper.GetTitleById(series.SeriesId); + + if(string.IsNullOrWhiteSpace(title)) + { + title = series.Title; + } + foreach (var indexer in indexers) { try @@ -66,7 +77,7 @@ namespace NzbDrone.Core.Providers.Jobs } else { - indexerResults = indexer.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber); + indexerResults = indexer.FetchEpisode(title, episode.SeasonNumber, episode.EpisodeNumber); } reports.AddRange(indexerResults); @@ -82,7 +93,7 @@ namespace NzbDrone.Core.Providers.Jobs reports.ForEach(c => { - c.Series = episode.Series; + c.Series = series; c.Episodes = new List { episode }; }); diff --git a/NzbDrone.Core/Providers/SeriesProvider.cs b/NzbDrone.Core/Providers/SeriesProvider.cs index 248947b45..b53b232db 100644 --- a/NzbDrone.Core/Providers/SeriesProvider.cs +++ b/NzbDrone.Core/Providers/SeriesProvider.cs @@ -105,10 +105,10 @@ namespace NzbDrone.Core.Providers { var normalizeTitle = Parser.NormalizeTitle(title); - var seriesId = SceneNameHelper.FindByName(normalizeTitle); + var seriesId = SceneNameHelper.GetIdByName(normalizeTitle); if (seriesId != 0) { - return GetSeries(seriesId); + return GetSeries(seriesId.Value); } return _repository.Single(s => s.CleanTitle == normalizeTitle);