parent
90f9dce44a
commit
a023732c1c
@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||||
|
using NzbDrone.Core.Organizer;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class EpisodeTitleSpecificationFixture : CoreTest<EpisodeTitleSpecification>
|
||||||
|
{
|
||||||
|
private Series _series;
|
||||||
|
private LocalEpisode _localEpisode;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_series = Builder<Series>.CreateNew()
|
||||||
|
.With(s => s.SeriesType = SeriesTypes.Standard)
|
||||||
|
.With(s => s.Path = @"C:\Test\TV\30 Rock".AsOsAgnostic())
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var episodes = Builder<Episode>.CreateListOfSize(1)
|
||||||
|
.All()
|
||||||
|
.With(e => e.SeasonNumber = 1)
|
||||||
|
.With(e => e.AirDateUtc = DateTime.UtcNow)
|
||||||
|
.Build()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_localEpisode = new LocalEpisode
|
||||||
|
{
|
||||||
|
Path = @"C:\Test\Unsorted\30 Rock\30.rock.s01e01.avi".AsOsAgnostic(),
|
||||||
|
Episodes = episodes,
|
||||||
|
Series = _series
|
||||||
|
};
|
||||||
|
|
||||||
|
Mocker.GetMock<IBuildFileNames>()
|
||||||
|
.Setup(s => s.RequiresEpisodeTitle(_series, episodes))
|
||||||
|
.Returns(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_reject_when_title_is_null()
|
||||||
|
{
|
||||||
|
_localEpisode.Episodes.First().Title = null;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_reject_when_title_is_TBA()
|
||||||
|
{
|
||||||
|
_localEpisode.Episodes.First().Title = "TBA";
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_accept_when_did_not_air_recently_but_title_is_TBA()
|
||||||
|
{
|
||||||
|
_localEpisode.Episodes.First().AirDateUtc = DateTime.UtcNow.AddDays(-7);
|
||||||
|
_localEpisode.Episodes.First().Title = "TBA";
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_accept_when_episode_title_is_not_required()
|
||||||
|
{
|
||||||
|
_localEpisode.Episodes.First().Title = "TBA";
|
||||||
|
|
||||||
|
Mocker.GetMock<IBuildFileNames>()
|
||||||
|
.Setup(s => s.RequiresEpisodeTitle(_series, _localEpisode.Episodes))
|
||||||
|
.Returns(false);
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.DecisionEngine;
|
||||||
|
using NzbDrone.Core.Download;
|
||||||
|
using NzbDrone.Core.Organizer;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
||||||
|
{
|
||||||
|
public class EpisodeTitleSpecification : IImportDecisionEngineSpecification
|
||||||
|
{
|
||||||
|
private readonly IBuildFileNames _buildFileNames;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public EpisodeTitleSpecification(IBuildFileNames buildFileNames, Logger logger)
|
||||||
|
{
|
||||||
|
_buildFileNames = buildFileNames;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem downloadClientItem)
|
||||||
|
{
|
||||||
|
if (!_buildFileNames.RequiresEpisodeTitle(localEpisode.Series, localEpisode.Episodes))
|
||||||
|
{
|
||||||
|
_logger.Debug("File name format does not require episode title, skipping check");
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var episode in localEpisode.Episodes)
|
||||||
|
{
|
||||||
|
var airDateUtc = episode.AirDateUtc;
|
||||||
|
var title = episode.Title;
|
||||||
|
|
||||||
|
if (airDateUtc.HasValue && airDateUtc.Value.Before(DateTime.UtcNow.AddDays(-1)))
|
||||||
|
{
|
||||||
|
_logger.Debug("Episode aired more than 1 day ago");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (title.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
_logger.Debug("Episode does not have a title and recently aired");
|
||||||
|
|
||||||
|
return Decision.Reject("Episode does not have a title and recently aired");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (title.Equals("TBA"))
|
||||||
|
{
|
||||||
|
_logger.Debug("Episode has a TBA title and recently aired");
|
||||||
|
|
||||||
|
return Decision.Reject("Episode has a TBA title and recently aired");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue