Compare commits
No commits in common. "episode-runtime-for-samples" and "develop" have entirely different histories.
episode-ru
...
develop
|
@ -39,29 +39,22 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
|
||||
Episodes = episodes,
|
||||
Series = _series,
|
||||
Quality = new QualityModel(Quality.HDTV720p),
|
||||
Quality = new QualityModel(Quality.HDTV720p)
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenRuntime(int seconds)
|
||||
{
|
||||
var runtime = new TimeSpan(0, 0, seconds);
|
||||
|
||||
Mocker.GetMock<IVideoFileInfoReader>()
|
||||
.Setup(s => s.GetRunTime(It.IsAny<string>()))
|
||||
.Returns(runtime);
|
||||
|
||||
_localEpisode.MediaInfo = Builder<MediaInfoModel>.CreateNew().With(m => m.RunTime = runtime).Build();
|
||||
.Returns(new TimeSpan(0, 0, seconds));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_season_zero()
|
||||
{
|
||||
_localEpisode.Episodes[0].SeasonNumber = 0;
|
||||
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.NotSample);
|
||||
ShouldBeNotSample();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -69,9 +62,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
{
|
||||
_localEpisode.Path = @"C:\Test\some.show.s01e01.flv";
|
||||
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.NotSample);
|
||||
ShouldBeNotSample();
|
||||
|
||||
Mocker.GetMock<IVideoFileInfoReader>().Verify(c => c.GetRunTime(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
@ -81,9 +72,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
{
|
||||
_localEpisode.Path = @"C:\Test\some.show.s01e01.strm";
|
||||
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.NotSample);
|
||||
ShouldBeNotSample();
|
||||
|
||||
Mocker.GetMock<IVideoFileInfoReader>().Verify(c => c.GetRunTime(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
@ -105,9 +94,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
{
|
||||
GivenRuntime(60);
|
||||
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.Sample);
|
||||
ShouldBeSample();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -115,9 +102,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
{
|
||||
GivenRuntime(600);
|
||||
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.NotSample);
|
||||
ShouldBeNotSample();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -126,9 +111,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
_series.Runtime = 6;
|
||||
GivenRuntime(299);
|
||||
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.NotSample);
|
||||
ShouldBeNotSample();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -137,9 +120,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
_series.Runtime = 2;
|
||||
GivenRuntime(60);
|
||||
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.NotSample);
|
||||
ShouldBeNotSample();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -148,9 +129,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
_series.Runtime = 2;
|
||||
GivenRuntime(10);
|
||||
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.Sample);
|
||||
ShouldBeSample();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -173,10 +152,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
GivenRuntime(600);
|
||||
_series.SeriesType = SeriesTypes.Daily;
|
||||
_localEpisode.Episodes[0].SeasonNumber = 0;
|
||||
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.NotSample);
|
||||
ShouldBeNotSample();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -185,33 +161,21 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|||
_series.SeriesType = SeriesTypes.Anime;
|
||||
_localEpisode.Episodes[0].SeasonNumber = 0;
|
||||
|
||||
ShouldBeNotSample();
|
||||
}
|
||||
|
||||
private void ShouldBeSample()
|
||||
{
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.Sample);
|
||||
}
|
||||
|
||||
private void ShouldBeNotSample()
|
||||
{
|
||||
Subject.IsSample(_localEpisode.Series,
|
||||
_localEpisode.Path,
|
||||
_localEpisode.IsSpecial).Should().Be(DetectSampleResult.NotSample);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_runtime_from_media_info()
|
||||
{
|
||||
GivenRuntime(120);
|
||||
|
||||
_localEpisode.Series.Runtime = 30;
|
||||
_localEpisode.Episodes.First().Runtime = 30;
|
||||
|
||||
Subject.IsSample(_localEpisode).Should().Be(DetectSampleResult.Sample);
|
||||
|
||||
Mocker.GetMock<IVideoFileInfoReader>().Verify(v => v.GetRunTime(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_runtime_from_episode_over_series()
|
||||
{
|
||||
GivenRuntime(120);
|
||||
|
||||
_localEpisode.Series.Runtime = 5;
|
||||
_localEpisode.Episodes.First().Runtime = 30;
|
||||
|
||||
Subject.IsSample(_localEpisode).Should().Be(DetectSampleResult.Sample);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Linq;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Core.MediaFiles.MediaInfo;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
||||
|
@ -10,7 +9,6 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
public interface IDetectSample
|
||||
{
|
||||
DetectSampleResult IsSample(Series series, string path, bool isSpecial);
|
||||
DetectSampleResult IsSample(LocalEpisode localEpisode);
|
||||
}
|
||||
|
||||
public class DetectSample : IDetectSample
|
||||
|
@ -25,51 +23,6 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
}
|
||||
|
||||
public DetectSampleResult IsSample(Series series, string path, bool isSpecial)
|
||||
{
|
||||
var extensionResult = IsSample(path, isSpecial);
|
||||
|
||||
if (extensionResult != DetectSampleResult.Indeterminate)
|
||||
{
|
||||
return extensionResult;
|
||||
}
|
||||
|
||||
var fileRuntime = _videoFileInfoReader.GetRunTime(path);
|
||||
|
||||
if (!fileRuntime.HasValue)
|
||||
{
|
||||
_logger.Error("Failed to get runtime from the file, make sure ffprobe is available");
|
||||
return DetectSampleResult.Indeterminate;
|
||||
}
|
||||
|
||||
return IsSample(path, fileRuntime.Value, series.Runtime);
|
||||
}
|
||||
|
||||
public DetectSampleResult IsSample(LocalEpisode localEpisode)
|
||||
{
|
||||
var extensionResult = IsSample(localEpisode.Path, localEpisode.IsSpecial);
|
||||
|
||||
if (extensionResult != DetectSampleResult.Indeterminate)
|
||||
{
|
||||
return extensionResult;
|
||||
}
|
||||
|
||||
var runtime = 0;
|
||||
|
||||
foreach (var episode in localEpisode.Episodes)
|
||||
{
|
||||
runtime += episode.Runtime > 0 ? episode.Runtime : localEpisode.Series.Runtime;
|
||||
}
|
||||
|
||||
if (localEpisode.MediaInfo == null)
|
||||
{
|
||||
_logger.Error("Failed to get runtime from the file, make sure ffprobe is available");
|
||||
return DetectSampleResult.Indeterminate;
|
||||
}
|
||||
|
||||
return IsSample(localEpisode.Path, localEpisode.MediaInfo.RunTime, runtime);
|
||||
}
|
||||
|
||||
private DetectSampleResult IsSample(string path, bool isSpecial)
|
||||
{
|
||||
if (isSpecial)
|
||||
{
|
||||
|
@ -91,45 +44,49 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
return DetectSampleResult.NotSample;
|
||||
}
|
||||
|
||||
// TODO: Use MediaInfo from the import process, no need to re-process the file again here
|
||||
var runTime = _videoFileInfoReader.GetRunTime(path);
|
||||
|
||||
if (!runTime.HasValue)
|
||||
{
|
||||
_logger.Error("Failed to get runtime from the file, make sure ffprobe is available");
|
||||
return DetectSampleResult.Indeterminate;
|
||||
}
|
||||
|
||||
private DetectSampleResult IsSample(string path, TimeSpan fileRuntime, int expectedRuntime)
|
||||
{
|
||||
var minimumRuntime = GetMinimumAllowedRuntime(expectedRuntime);
|
||||
var minimumRuntime = GetMinimumAllowedRuntime(series);
|
||||
|
||||
if (fileRuntime.TotalMinutes.Equals(0))
|
||||
if (runTime.Value.TotalMinutes.Equals(0))
|
||||
{
|
||||
_logger.Error("[{0}] has a runtime of 0, is it a valid video file?", path);
|
||||
return DetectSampleResult.Sample;
|
||||
}
|
||||
|
||||
if (fileRuntime.TotalSeconds < minimumRuntime)
|
||||
if (runTime.Value.TotalSeconds < minimumRuntime)
|
||||
{
|
||||
_logger.Debug("[{0}] appears to be a sample. Runtime: {1} seconds. Expected at least: {2} seconds", path, fileRuntime, minimumRuntime);
|
||||
_logger.Debug("[{0}] appears to be a sample. Runtime: {1} seconds. Expected at least: {2} seconds", path, runTime, minimumRuntime);
|
||||
return DetectSampleResult.Sample;
|
||||
}
|
||||
|
||||
_logger.Debug("[{0}] does not appear to be a sample. Runtime {1} seconds is more than minimum of {2} seconds", path, fileRuntime, minimumRuntime);
|
||||
_logger.Debug("[{0}] does not appear to be a sample. Runtime {1} seconds is more than minimum of {2} seconds", path, runTime, minimumRuntime);
|
||||
return DetectSampleResult.NotSample;
|
||||
}
|
||||
|
||||
private int GetMinimumAllowedRuntime(int runtime)
|
||||
private int GetMinimumAllowedRuntime(Series series)
|
||||
{
|
||||
// Anime short - 15 seconds
|
||||
if (runtime <= 3)
|
||||
if (series.Runtime <= 3)
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
|
||||
// Webisodes - 90 seconds
|
||||
if (runtime <= 10)
|
||||
if (series.Runtime <= 10)
|
||||
{
|
||||
return 90;
|
||||
}
|
||||
|
||||
// 30 minute episodes - 5 minutes
|
||||
if (runtime <= 30)
|
||||
if (series.Runtime <= 30)
|
||||
{
|
||||
return 300;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|||
|
||||
try
|
||||
{
|
||||
var sample = _detectSample.IsSample(localEpisode);
|
||||
var sample = _detectSample.IsSample(localEpisode.Series, localEpisode.Path, localEpisode.IsSpecial);
|
||||
|
||||
if (sample == DetectSampleResult.Sample)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue