Parsing service code (and tests) for absolute numbered episodes

pull/3113/head
Cyberlane 11 years ago committed by Mark McDowall
parent d13b41313f
commit 44c1bc632e

@ -38,7 +38,8 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
{
SeriesTitle = _series.Title,
SeasonNumber = 1,
EpisodeNumbers = new[] { 1 }
EpisodeNumbers = new[] { 1 },
AbsoluteEpisodeNumbers = new int[0]
};
_singleEpisodeSearchCriteria = new SingleEpisodeSearchCriteria
@ -69,6 +70,11 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
_series.UseSceneNumbering = true;
}
private void GivenAbsoluteNumberingSeries()
{
_parsedEpisodeInfo.AbsoluteEpisodeNumbers = new[] { 1 };
}
[Test]
public void should_get_daily_episode_episode_when_search_criteria_is_null()
{
@ -105,6 +111,17 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
.Verify(v => v.FindEpisode(It.IsAny<Int32>(), It.IsAny<String>()), Times.Once());
}
[Test]
public void should_use_search_criteria_episode_when_it_matches_absolute()
{
GivenAbsoluteNumberingSeries();
Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria);
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.FindEpisode(It.IsAny<Int32>(), It.IsAny<String>()), Times.Never());
}
[Test]
public void should_use_scene_numbering_when_series_uses_scene_numbering()
{

@ -20,6 +20,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
.With(e => e.SeasonNumber = 1)
.With(e => e.SceneSeasonNumber = 2)
.With(e => e.EpisodeNumber = 3)
.With(e => e.AbsoluteEpisodeNumber = 3)
.With(e => e.SceneEpisodeNumber = 4)
.Build();
@ -51,5 +52,14 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
.Should()
.BeNull();
}
[Test]
public void should_find_episode_by_absolute_numbering()
{
Subject.Find(_episode.SeriesId, _episode.AbsoluteEpisodeNumber.Value)
.Id
.Should()
.Be(_episode.Id);
}
}
}

@ -41,5 +41,10 @@ namespace NzbDrone.Core.Parser.Model
{
return !String.IsNullOrWhiteSpace(AirDate);
}
public bool IsAbsoluteNumbering()
{
return AbsoluteEpisodeNumbers.Length > 0;
}
}
}

@ -129,6 +129,28 @@ namespace NzbDrone.Core.Parser
return result;
}
if (parsedEpisodeInfo.IsAbsoluteNumbering())
{
foreach (var absoluteEpisodeNumber in parsedEpisodeInfo.AbsoluteEpisodeNumbers)
{
var episodeInfo = _episodeService.FindEpisode(series.Id, absoluteEpisodeNumber);
if (episodeInfo != null)
{
_logger.Info("Using absolute episode number {0} for: {1} - Scene: {2}x{3:00} - TVDB: {4}x{5:00}",
absoluteEpisodeNumber,
series.Title,
episodeInfo.SceneSeasonNumber,
episodeInfo.SceneEpisodeNumber,
episodeInfo.SeasonNumber,
episodeInfo.EpisodeNumber);
result.Add(episodeInfo);
}
}
return result;
}
if (parsedEpisodeInfo.EpisodeNumbers == null)
return result;

@ -11,6 +11,7 @@ namespace NzbDrone.Core.Tv
public interface IEpisodeRepository : IBasicRepository<Episode>
{
Episode Find(int seriesId, int season, int episodeNumber);
Episode Find(int seriesId, int absoluteEpisodeNumber);
Episode Get(int seriesId, String date);
Episode Find(int seriesId, String date);
List<Episode> GetEpisodes(int seriesId);
@ -39,6 +40,11 @@ namespace NzbDrone.Core.Tv
return Query.SingleOrDefault(s => s.SeriesId == seriesId && s.SeasonNumber == season && s.EpisodeNumber == episodeNumber);
}
public Episode Find(int seriesId, int absoluteEpisodeNumber)
{
return Query.SingleOrDefault(s => s.SeriesId == seriesId && s.AbsoluteEpisodeNumber == absoluteEpisodeNumber);
}
public Episode Get(int seriesId, String date)
{
return Query.Single(s => s.SeriesId == seriesId && s.AirDate == date);

@ -14,6 +14,7 @@ namespace NzbDrone.Core.Tv
{
Episode GetEpisode(int id);
Episode FindEpisode(int seriesId, int seasonNumber, int episodeNumber, bool useScene = false);
Episode FindEpisode(int seriesId, int absoluteEpisodeNumber);
Episode GetEpisode(int seriesId, String date);
Episode FindEpisode(int seriesId, String date);
List<Episode> GetEpisodeBySeries(int seriesId);
@ -62,6 +63,11 @@ namespace NzbDrone.Core.Tv
return _episodeRepository.Find(seriesId, seasonNumber, episodeNumber);
}
public Episode FindEpisode(int seriesId, int absoluteEpisodeNumber)
{
return _episodeRepository.Find(seriesId, absoluteEpisodeNumber);
}
public Episode GetEpisode(int seriesId, String date)
{
return _episodeRepository.Get(seriesId, date);

Loading…
Cancel
Save