New: Delay import is absolute episode number is required and is missing for EpisodeFormatpull/2789/head
parent
f345977e3f
commit
5f6f4915a1
@ -0,0 +1,77 @@
|
|||||||
|
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 AbsoluteEpisodeNumberSpecificationFixture : CoreTest<AbsoluteEpisodeNumberSpecification>
|
||||||
|
{
|
||||||
|
private Series _series;
|
||||||
|
private LocalEpisode _localEpisode;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_series = Builder<Series>.CreateNew()
|
||||||
|
.With(s => s.SeriesType = SeriesTypes.Anime)
|
||||||
|
.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.RequiresAbsoluteEpisodeNumber(_series, episodes))
|
||||||
|
.Returns(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_reject_when_absolute_episode_number_is_null()
|
||||||
|
{
|
||||||
|
_localEpisode.Episodes.First().AbsoluteEpisodeNumber = null;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_accept_when_did_not_air_recently_but_absolute_episode_number_is_null()
|
||||||
|
{
|
||||||
|
_localEpisode.Episodes.First().AirDateUtc = DateTime.UtcNow.AddDays(-7);
|
||||||
|
_localEpisode.Episodes.First().AbsoluteEpisodeNumber = null;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_accept_when_absolute_episode_number_is_not_required()
|
||||||
|
{
|
||||||
|
_localEpisode.Episodes.First().AbsoluteEpisodeNumber = null;
|
||||||
|
|
||||||
|
Mocker.GetMock<IBuildFileNames>()
|
||||||
|
.Setup(s => s.RequiresAbsoluteEpisodeNumber(_series, _localEpisode.Episodes))
|
||||||
|
.Returns(false);
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Organizer;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class RequiresAbsoluteEpisodeNumberFixture : CoreTest<FileNameBuilder>
|
||||||
|
{
|
||||||
|
private Series _series;
|
||||||
|
private Episode _episode;
|
||||||
|
private NamingConfig _namingConfig;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_series = Builder<Series>
|
||||||
|
.CreateNew()
|
||||||
|
.With(s => s.SeriesType = SeriesTypes.Anime)
|
||||||
|
.With(s => s.Title = "South Park")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_episode = Builder<Episode>.CreateNew()
|
||||||
|
.With(e => e.Title = "City Sushi")
|
||||||
|
.With(e => e.SeasonNumber = 15)
|
||||||
|
.With(e => e.EpisodeNumber = 6)
|
||||||
|
.With(e => e.AbsoluteEpisodeNumber = 100)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_namingConfig = NamingConfig.Default;
|
||||||
|
_namingConfig.RenameEpisodes = true;
|
||||||
|
|
||||||
|
Mocker.GetMock<INamingConfigService>()
|
||||||
|
.Setup(c => c.GetConfig()).Returns(_namingConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_false_when_absolute_episode_number_is_not_part_of_the_pattern()
|
||||||
|
{
|
||||||
|
_namingConfig.AnimeEpisodeFormat = "{Series Title} S{season:00}E{episode:00}";
|
||||||
|
Subject.RequiresAbsoluteEpisodeNumber(_series, new List<Episode> { _episode }).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_when_absolute_episode_number_is_part_of_the_pattern()
|
||||||
|
{
|
||||||
|
_namingConfig.AnimeEpisodeFormat = "{Series Title} {absolute:00}";
|
||||||
|
Subject.RequiresAbsoluteEpisodeNumber(_series, new List<Episode> { _episode }).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;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
||||||
|
{
|
||||||
|
public class AbsoluteEpisodeNumberSpecification : IImportDecisionEngineSpecification
|
||||||
|
{
|
||||||
|
private readonly IBuildFileNames _buildFileNames;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public AbsoluteEpisodeNumberSpecification(IBuildFileNames buildFileNames, Logger logger)
|
||||||
|
{
|
||||||
|
_buildFileNames = buildFileNames;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem downloadClientItem)
|
||||||
|
{
|
||||||
|
if (localEpisode.Series.SeriesType != SeriesTypes.Anime)
|
||||||
|
{
|
||||||
|
_logger.Debug("Series type is not Anime, skipping check");
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_buildFileNames.RequiresAbsoluteEpisodeNumber(localEpisode.Series, localEpisode.Episodes))
|
||||||
|
{
|
||||||
|
_logger.Debug("File name format does not require absolute episode number, skipping check");
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var episode in localEpisode.Episodes)
|
||||||
|
{
|
||||||
|
var airDateUtc = episode.AirDateUtc;
|
||||||
|
var absoluteEpisodeNumber = episode.AbsoluteEpisodeNumber;
|
||||||
|
|
||||||
|
if (airDateUtc.HasValue && airDateUtc.Value.Before(DateTime.UtcNow.AddDays(-1)))
|
||||||
|
{
|
||||||
|
_logger.Debug("Episode aired more than 1 day ago");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!absoluteEpisodeNumber.HasValue)
|
||||||
|
{
|
||||||
|
_logger.Debug("Episode does not have an absolute episode number and recently aired");
|
||||||
|
|
||||||
|
return Decision.Reject("Episode does not have an absolute episode number and recently aired");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue