diff --git a/src/NzbDrone.Core.Test/DataAugmentation/Scene/SceneMappingServiceFixture.cs b/src/NzbDrone.Core.Test/DataAugmentation/Scene/SceneMappingServiceFixture.cs index 063365886..af75c74d5 100644 --- a/src/NzbDrone.Core.Test/DataAugmentation/Scene/SceneMappingServiceFixture.cs +++ b/src/NzbDrone.Core.Test/DataAugmentation/Scene/SceneMappingServiceFixture.cs @@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene [Test] public void should_refresh_cache_if_cache_is_empty_when_looking_for_tvdb_id() { - Subject.FindTvDbId("title"); + Subject.FindTvdbId("title"); Mocker.GetMock() .Verify(v => v.All(), Times.Once()); @@ -129,7 +129,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene Mocker.GetMock() .Verify(v => v.All(), Times.Once()); - Subject.FindTvDbId("title"); + Subject.FindTvdbId("title"); Mocker.GetMock() .Verify(v => v.All(), Times.Once()); @@ -195,7 +195,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene Mocker.GetMock().Setup(c => c.All()).Returns(mappings); - var tvdbId = Subject.FindTvDbId(parseTitle); + var tvdbId = Subject.FindTvdbId(parseTitle); var seasonNumber = Subject.GetSeasonNumber(parseTitle); tvdbId.Should().Be(100); @@ -218,7 +218,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene foreach (var sceneMapping in _fakeMappings) { Subject.GetSceneNames(sceneMapping.TvdbId, _fakeMappings.Select(m => m.SeasonNumber)).Should().Contain(sceneMapping.SearchTerm); - Subject.FindTvDbId(sceneMapping.ParseTerm).Should().Be(sceneMapping.TvdbId); + Subject.FindTvdbId(sceneMapping.ParseTerm).Should().Be(sceneMapping.TvdbId); } } } diff --git a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs index 6f1d84a4b..bb9aa5f7c 100644 --- a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; +using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Core.DataAugmentation.Scene; @@ -92,6 +93,23 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests .Verify(v => v.FindByTvRageId(It.IsAny()), Times.Once()); } + [Test] + public void should_not_use_tvrageid_when_scene_naming_exception_exists() + { + GivenMatchByTvRageId(); + + Mocker.GetMock() + .Setup(v => v.FindTvdbId(It.IsAny())) + .Returns(10); + + var result = Subject.Map(_parsedEpisodeInfo, _series.TvRageId); + + Mocker.GetMock() + .Verify(v => v.FindByTvRageId(It.IsAny()), Times.Never()); + + result.Series.Should().BeNull(); + } + [Test] public void should_use_search_criteria_series_title() { @@ -115,7 +133,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests } [Test] - public void should_FindByTvRageId_when_search_criteria_and_FIndByTitle_matching_fails() + public void should_FindByTvRageId_when_search_criteria_and_FindByTitle_matching_fails() { GivenParseResultSeriesDoesntMatchSearchCriteria(); @@ -129,7 +147,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests public void should_use_tvdbid_matching_when_alias_is_found() { Mocker.GetMock() - .Setup(s => s.FindTvDbId(It.IsAny())) + .Setup(s => s.FindTvdbId(It.IsAny())) .Returns(_series.TvdbId); Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs index 082e9560f..736100e82 100644 --- a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -15,7 +15,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene public interface ISceneMappingService { List GetSceneNames(int tvdbId, IEnumerable seasonNumbers); - Nullable FindTvDbId(string title); + Nullable FindTvdbId(string title); List FindByTvdbId(int tvdbId); Nullable GetSeasonNumber(string title); } @@ -61,9 +61,9 @@ namespace NzbDrone.Core.DataAugmentation.Scene .Select(m => m.SearchTerm).Distinct().ToList()); } - public Nullable FindTvDbId(string title) + public Nullable FindTvdbId(string title) { - var mapping = FindTvdbId(title); + var mapping = FindMapping(title); if (mapping == null) return null; @@ -90,7 +90,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene public Nullable GetSeasonNumber(string title) { - var mapping = FindTvdbId(title); + var mapping = FindMapping(title); if (mapping == null) return null; @@ -147,7 +147,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene _eventAggregator.PublishEvent(new SceneMappingsUpdatedEvent()); } - private SceneMapping FindTvdbId(string title) + private SceneMapping FindMapping(string title) { if (_getTvdbIdCache.Count == 0) { diff --git a/src/NzbDrone.Core/Parser/ParsingService.cs b/src/NzbDrone.Core/Parser/ParsingService.cs index 0610d37f7..c549733b3 100644 --- a/src/NzbDrone.Core/Parser/ParsingService.cs +++ b/src/NzbDrone.Core/Parser/ParsingService.cs @@ -116,8 +116,7 @@ namespace NzbDrone.Core.Parser ParsedEpisodeInfo = parsedEpisodeInfo, }; - var series = searchCriteria == null ? GetSeries(parsedEpisodeInfo, tvRageId) : - GetSeries(parsedEpisodeInfo, tvRageId, searchCriteria); + var series = GetSeries(parsedEpisodeInfo, tvRageId, searchCriteria); if (series == null) { @@ -291,7 +290,7 @@ namespace NzbDrone.Core.Parser { if (searchCriteria != null) { - var tvdbId = _sceneMappingService.FindTvDbId(title); + var tvdbId = _sceneMappingService.FindTvdbId(title); if (tvdbId.HasValue) { if (searchCriteria.Series.TvdbId == tvdbId) @@ -354,33 +353,43 @@ namespace NzbDrone.Core.Parser private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvRageId, SearchCriteriaBase searchCriteria) { - var tvdbId = _sceneMappingService.FindTvDbId(parsedEpisodeInfo.SeriesTitle); + Series series = null; + + var tvdbId = _sceneMappingService.FindTvdbId(parsedEpisodeInfo.SeriesTitle); if (tvdbId.HasValue) { - if (searchCriteria.Series.TvdbId == tvdbId) + if (searchCriteria != null && searchCriteria.Series.TvdbId == tvdbId) { return searchCriteria.Series; } - } - if (parsedEpisodeInfo.SeriesTitle.CleanSeriesTitle() == searchCriteria.Series.CleanTitle) - { - return searchCriteria.Series; + series = _seriesService.FindByTvdbId(tvdbId.Value); + + if (series == null) + { + _logger.Debug("No matching series {0}", parsedEpisodeInfo.SeriesTitle); + return null; + } + + return series; } - if (tvRageId > 0 && tvRageId == searchCriteria.Series.TvRageId) + if (searchCriteria != null) { - //TODO: If series is found by TvRageId, we should report it as a scene naming exception, since it will fail to import - return searchCriteria.Series; - } + if (searchCriteria.Series.CleanTitle == parsedEpisodeInfo.SeriesTitle.CleanSeriesTitle()) + { + return searchCriteria.Series; + } - return GetSeries(parsedEpisodeInfo, tvRageId); - } + if (tvRageId > 0 && tvRageId == searchCriteria.Series.TvRageId) + { + //TODO: If series is found by TvRageId, we should report it as a scene naming exception, since it will fail to import + return searchCriteria.Series; + } + } - private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvRageId) - { - var series = _seriesService.FindByTitle(parsedEpisodeInfo.SeriesTitle); + series = _seriesService.FindByTitle(parsedEpisodeInfo.SeriesTitle); if (series == null && tvRageId > 0) { diff --git a/src/NzbDrone.Core/Tv/SeriesService.cs b/src/NzbDrone.Core/Tv/SeriesService.cs index c61bc15e8..8baee08cf 100644 --- a/src/NzbDrone.Core/Tv/SeriesService.cs +++ b/src/NzbDrone.Core/Tv/SeriesService.cs @@ -18,6 +18,7 @@ namespace NzbDrone.Core.Tv Series GetSeries(int seriesId); List GetSeries(IEnumerable seriesIds); Series AddSeries(Series newSeries); + Series FindByTvdbId(int tvdbId); Series FindByTvRageId(int tvRageId); Series FindByTitle(string title); Series FindByTitle(string title, int year); @@ -87,6 +88,11 @@ namespace NzbDrone.Core.Tv return newSeries; } + public Series FindByTvdbId(int tvRageId) + { + return _seriesRepository.FindByTvdbId(tvRageId); + } + public Series FindByTvRageId(int tvRageId) { return _seriesRepository.FindByTvRageId(tvRageId); @@ -94,7 +100,7 @@ namespace NzbDrone.Core.Tv public Series FindByTitle(string title) { - var tvdbId = _sceneMappingService.FindTvDbId(title); + var tvdbId = _sceneMappingService.FindTvdbId(title); if (tvdbId.HasValue) {