Fixed: Should ignore indexer provided tvrageid when scene naming exception exists.

pull/3113/head
Taloth Saldono 9 years ago
parent c56cf8860e
commit a84f39bb48

@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
[Test] [Test]
public void should_refresh_cache_if_cache_is_empty_when_looking_for_tvdb_id() public void should_refresh_cache_if_cache_is_empty_when_looking_for_tvdb_id()
{ {
Subject.FindTvDbId("title"); Subject.FindTvdbId("title");
Mocker.GetMock<ISceneMappingRepository>() Mocker.GetMock<ISceneMappingRepository>()
.Verify(v => v.All(), Times.Once()); .Verify(v => v.All(), Times.Once());
@ -129,7 +129,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
Mocker.GetMock<ISceneMappingRepository>() Mocker.GetMock<ISceneMappingRepository>()
.Verify(v => v.All(), Times.Once()); .Verify(v => v.All(), Times.Once());
Subject.FindTvDbId("title"); Subject.FindTvdbId("title");
Mocker.GetMock<ISceneMappingRepository>() Mocker.GetMock<ISceneMappingRepository>()
.Verify(v => v.All(), Times.Once()); .Verify(v => v.All(), Times.Once());
@ -195,7 +195,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings); Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
var tvdbId = Subject.FindTvDbId(parseTitle); var tvdbId = Subject.FindTvdbId(parseTitle);
var seasonNumber = Subject.GetSeasonNumber(parseTitle); var seasonNumber = Subject.GetSeasonNumber(parseTitle);
tvdbId.Should().Be(100); tvdbId.Should().Be(100);
@ -218,7 +218,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
foreach (var sceneMapping in _fakeMappings) foreach (var sceneMapping in _fakeMappings)
{ {
Subject.GetSceneNames(sceneMapping.TvdbId, _fakeMappings.Select(m => m.SeasonNumber)).Should().Contain(sceneMapping.SearchTerm); 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);
} }
} }
} }

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.DataAugmentation.Scene; using NzbDrone.Core.DataAugmentation.Scene;
@ -92,6 +93,23 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
.Verify(v => v.FindByTvRageId(It.IsAny<Int32>()), Times.Once()); .Verify(v => v.FindByTvRageId(It.IsAny<Int32>()), Times.Once());
} }
[Test]
public void should_not_use_tvrageid_when_scene_naming_exception_exists()
{
GivenMatchByTvRageId();
Mocker.GetMock<ISceneMappingService>()
.Setup(v => v.FindTvdbId(It.IsAny<string>()))
.Returns(10);
var result = Subject.Map(_parsedEpisodeInfo, _series.TvRageId);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.FindByTvRageId(It.IsAny<Int32>()), Times.Never());
result.Series.Should().BeNull();
}
[Test] [Test]
public void should_use_search_criteria_series_title() public void should_use_search_criteria_series_title()
{ {
@ -115,7 +133,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
} }
[Test] [Test]
public void should_FindByTvRageId_when_search_criteria_and_FIndByTitle_matching_fails() public void should_FindByTvRageId_when_search_criteria_and_FindByTitle_matching_fails()
{ {
GivenParseResultSeriesDoesntMatchSearchCriteria(); GivenParseResultSeriesDoesntMatchSearchCriteria();
@ -129,7 +147,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
public void should_use_tvdbid_matching_when_alias_is_found() public void should_use_tvdbid_matching_when_alias_is_found()
{ {
Mocker.GetMock<ISceneMappingService>() Mocker.GetMock<ISceneMappingService>()
.Setup(s => s.FindTvDbId(It.IsAny<String>())) .Setup(s => s.FindTvdbId(It.IsAny<String>()))
.Returns(_series.TvdbId); .Returns(_series.TvdbId);
Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria);

@ -15,7 +15,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
public interface ISceneMappingService public interface ISceneMappingService
{ {
List<String> GetSceneNames(int tvdbId, IEnumerable<Int32> seasonNumbers); List<String> GetSceneNames(int tvdbId, IEnumerable<Int32> seasonNumbers);
Nullable<int> FindTvDbId(string title); Nullable<int> FindTvdbId(string title);
List<SceneMapping> FindByTvdbId(int tvdbId); List<SceneMapping> FindByTvdbId(int tvdbId);
Nullable<Int32> GetSeasonNumber(string title); Nullable<Int32> GetSeasonNumber(string title);
} }
@ -61,9 +61,9 @@ namespace NzbDrone.Core.DataAugmentation.Scene
.Select(m => m.SearchTerm).Distinct().ToList()); .Select(m => m.SearchTerm).Distinct().ToList());
} }
public Nullable<Int32> FindTvDbId(string title) public Nullable<Int32> FindTvdbId(string title)
{ {
var mapping = FindTvdbId(title); var mapping = FindMapping(title);
if (mapping == null) if (mapping == null)
return null; return null;
@ -90,7 +90,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
public Nullable<Int32> GetSeasonNumber(string title) public Nullable<Int32> GetSeasonNumber(string title)
{ {
var mapping = FindTvdbId(title); var mapping = FindMapping(title);
if (mapping == null) if (mapping == null)
return null; return null;
@ -147,7 +147,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
_eventAggregator.PublishEvent(new SceneMappingsUpdatedEvent()); _eventAggregator.PublishEvent(new SceneMappingsUpdatedEvent());
} }
private SceneMapping FindTvdbId(string title) private SceneMapping FindMapping(string title)
{ {
if (_getTvdbIdCache.Count == 0) if (_getTvdbIdCache.Count == 0)
{ {

@ -116,8 +116,7 @@ namespace NzbDrone.Core.Parser
ParsedEpisodeInfo = parsedEpisodeInfo, ParsedEpisodeInfo = parsedEpisodeInfo,
}; };
var series = searchCriteria == null ? GetSeries(parsedEpisodeInfo, tvRageId) : var series = GetSeries(parsedEpisodeInfo, tvRageId, searchCriteria);
GetSeries(parsedEpisodeInfo, tvRageId, searchCriteria);
if (series == null) if (series == null)
{ {
@ -291,7 +290,7 @@ namespace NzbDrone.Core.Parser
{ {
if (searchCriteria != null) if (searchCriteria != null)
{ {
var tvdbId = _sceneMappingService.FindTvDbId(title); var tvdbId = _sceneMappingService.FindTvdbId(title);
if (tvdbId.HasValue) if (tvdbId.HasValue)
{ {
if (searchCriteria.Series.TvdbId == tvdbId) if (searchCriteria.Series.TvdbId == tvdbId)
@ -354,33 +353,43 @@ namespace NzbDrone.Core.Parser
private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvRageId, SearchCriteriaBase searchCriteria) 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 (tvdbId.HasValue)
{ {
if (searchCriteria.Series.TvdbId == tvdbId) if (searchCriteria != null && searchCriteria.Series.TvdbId == tvdbId)
{ {
return searchCriteria.Series; return searchCriteria.Series;
} }
}
if (parsedEpisodeInfo.SeriesTitle.CleanSeriesTitle() == searchCriteria.Series.CleanTitle) series = _seriesService.FindByTvdbId(tvdbId.Value);
{
return searchCriteria.Series; 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 if (searchCriteria.Series.CleanTitle == parsedEpisodeInfo.SeriesTitle.CleanSeriesTitle())
return searchCriteria.Series; {
} 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) series = _seriesService.FindByTitle(parsedEpisodeInfo.SeriesTitle);
{
var series = _seriesService.FindByTitle(parsedEpisodeInfo.SeriesTitle);
if (series == null && tvRageId > 0) if (series == null && tvRageId > 0)
{ {

@ -18,6 +18,7 @@ namespace NzbDrone.Core.Tv
Series GetSeries(int seriesId); Series GetSeries(int seriesId);
List<Series> GetSeries(IEnumerable<int> seriesIds); List<Series> GetSeries(IEnumerable<int> seriesIds);
Series AddSeries(Series newSeries); Series AddSeries(Series newSeries);
Series FindByTvdbId(int tvdbId);
Series FindByTvRageId(int tvRageId); Series FindByTvRageId(int tvRageId);
Series FindByTitle(string title); Series FindByTitle(string title);
Series FindByTitle(string title, int year); Series FindByTitle(string title, int year);
@ -87,6 +88,11 @@ namespace NzbDrone.Core.Tv
return newSeries; return newSeries;
} }
public Series FindByTvdbId(int tvRageId)
{
return _seriesRepository.FindByTvdbId(tvRageId);
}
public Series FindByTvRageId(int tvRageId) public Series FindByTvRageId(int tvRageId)
{ {
return _seriesRepository.FindByTvRageId(tvRageId); return _seriesRepository.FindByTvRageId(tvRageId);
@ -94,7 +100,7 @@ namespace NzbDrone.Core.Tv
public Series FindByTitle(string title) public Series FindByTitle(string title)
{ {
var tvdbId = _sceneMappingService.FindTvDbId(title); var tvdbId = _sceneMappingService.FindTvdbId(title);
if (tvdbId.HasValue) if (tvdbId.HasValue)
{ {

Loading…
Cancel
Save