1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

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

This commit is contained in:
Taloth Saldono 2015-08-03 19:19:59 +02:00
parent c56cf8860e
commit a84f39bb48
5 changed files with 67 additions and 34 deletions
src
NzbDrone.Core.Test
DataAugmentation/Scene
ParserTests/ParsingServiceTests
NzbDrone.Core

View File

@ -108,7 +108,7 @@ public void should_get_mappings_for_all_providers()
[Test]
public void should_refresh_cache_if_cache_is_empty_when_looking_for_tvdb_id()
{
Subject.FindTvDbId("title");
Subject.FindTvdbId("title");
Mocker.GetMock<ISceneMappingRepository>()
.Verify(v => v.All(), Times.Once());
@ -129,7 +129,7 @@ public void should_not_refresh_cache_if_cache_is_not_empty_when_looking_for_tvdb
Mocker.GetMock<ISceneMappingRepository>()
.Verify(v => v.All(), Times.Once());
Subject.FindTvDbId("title");
Subject.FindTvdbId("title");
Mocker.GetMock<ISceneMappingRepository>()
.Verify(v => v.All(), Times.Once());
@ -195,7 +195,7 @@ public void should_return_single_match(string parseTitle, string title, int expe
Mocker.GetMock<ISceneMappingRepository>().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 @@ private void AssertMappingUpdated()
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);
}
}
}

View File

@ -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 @@ public void should_use_tvrageid_when_series_title_lookup_fails()
.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]
public void should_use_search_criteria_series_title()
{
@ -115,7 +133,7 @@ public void should_FindByTitle_when_search_criteria_matching_fails()
}
[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 @@ public void should_FindByTvRageId_when_search_criteria_and_FIndByTitle_matching_
public void should_use_tvdbid_matching_when_alias_is_found()
{
Mocker.GetMock<ISceneMappingService>()
.Setup(s => s.FindTvDbId(It.IsAny<String>()))
.Setup(s => s.FindTvdbId(It.IsAny<String>()))
.Returns(_series.TvdbId);
Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria);

View File

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

View File

@ -116,8 +116,7 @@ public RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, Int32 tvRageId, Se
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 @@ public ParsedEpisodeInfo ParseSpecialEpisodeTitle(string title, int tvRageId, Se
{
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 @@ private ParsedEpisodeInfo ParseSpecialEpisodeTitle(string title, Series series)
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;
}
series = _seriesService.FindByTvdbId(tvdbId.Value);
if (series == null)
{
_logger.Debug("No matching series {0}", parsedEpisodeInfo.SeriesTitle);
return null;
}
return series;
}
if (searchCriteria != null)
{
if (searchCriteria.Series.CleanTitle == parsedEpisodeInfo.SeriesTitle.CleanSeriesTitle())
{
return searchCriteria.Series;
}
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;
}
}
if (parsedEpisodeInfo.SeriesTitle.CleanSeriesTitle() == searchCriteria.Series.CleanTitle)
{
return searchCriteria.Series;
}
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;
}
return GetSeries(parsedEpisodeInfo, tvRageId);
}
private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvRageId)
{
var series = _seriesService.FindByTitle(parsedEpisodeInfo.SeriesTitle);
series = _seriesService.FindByTitle(parsedEpisodeInfo.SeriesTitle);
if (series == null && tvRageId > 0)
{

View File

@ -18,6 +18,7 @@ public interface ISeriesService
Series GetSeries(int seriesId);
List<Series> GetSeries(IEnumerable<int> 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 @@ public Series AddSeries(Series newSeries)
return newSeries;
}
public Series FindByTvdbId(int tvRageId)
{
return _seriesRepository.FindByTvdbId(tvRageId);
}
public Series FindByTvRageId(int tvRageId)
{
return _seriesRepository.FindByTvRageId(tvRageId);
@ -94,7 +100,7 @@ public Series FindByTvRageId(int tvRageId)
public Series FindByTitle(string title)
{
var tvdbId = _sceneMappingService.FindTvDbId(title);
var tvdbId = _sceneMappingService.FindTvdbId(title);
if (tvdbId.HasValue)
{