New: Reject File if Sample Check Indeterminate

pull/2/head
Qstick 4 years ago
parent 1c85bd96f8
commit 2390ab98fa

@ -256,8 +256,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDetectSample>()
.Setup(s => s.IsSample(It.IsAny<Movie>(),
It.IsAny<string>(),
It.IsAny<bool>()))
It.IsAny<string>()))
.Returns(DetectSampleResult.Sample);
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
@ -326,8 +325,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDetectSample>()
.Setup(s => s.IsSample(It.IsAny<Movie>(),
It.IsAny<string>(),
It.IsAny<bool>()))
It.IsAny<string>()))
.Returns(DetectSampleResult.Sample);
Mocker.GetMock<IDiskProvider>()
@ -434,8 +432,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDetectSample>()
.Setup(s => s.IsSample(It.IsAny<Movie>(),
It.IsAny<string>(),
It.IsAny<bool>()))
It.IsAny<string>()))
.Returns(DetectSampleResult.Sample);
Mocker.GetMock<IDiskProvider>()

@ -97,8 +97,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport
GivenRuntime(120);
Subject.IsSample(_localMovie.Movie,
_localMovie.Path,
false);
_localMovie.Path);
Mocker.GetMock<IVideoFileInfoReader>().Verify(v => v.GetRunTime(It.IsAny<string>()), Times.Once());
}
@ -154,8 +153,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport
.Returns((TimeSpan?)null);
Subject.IsSample(_localMovie.Movie,
_localMovie.Path,
false).Should().Be(DetectSampleResult.Indeterminate);
_localMovie.Path).Should().Be(DetectSampleResult.Indeterminate);
ExceptionVerification.ExpectedErrors(1);
}
@ -163,15 +161,13 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport
private void ShouldBeSample()
{
Subject.IsSample(_localMovie.Movie,
_localMovie.Path,
false).Should().Be(DetectSampleResult.Sample);
_localMovie.Path).Should().Be(DetectSampleResult.Sample);
}
private void ShouldBeNotSample()
{
Subject.IsSample(_localMovie.Movie,
_localMovie.Path,
false).Should().Be(DetectSampleResult.NotSample);
_localMovie.Path).Should().Be(DetectSampleResult.NotSample);
}
}
}

@ -131,7 +131,7 @@ namespace NzbDrone.Core.MediaFiles
return false;
}
if (_detectSample.IsSample(movie, videoFile, false) != DetectSampleResult.Sample)
if (_detectSample.IsSample(movie, videoFile) != DetectSampleResult.Sample)
{
_logger.Warn("Non-sample file detected: [{0}]", videoFile);
return false;

@ -9,7 +9,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
{
public interface IDetectSample
{
DetectSampleResult IsSample(Movie movie, string path, bool isSpecial);
DetectSampleResult IsSample(Movie movie, string path);
}
public class DetectSample : IDetectSample
@ -23,14 +23,8 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
_logger = logger;
}
public DetectSampleResult IsSample(Movie movie, string path, bool isSpecial)
public DetectSampleResult IsSample(Movie movie, string path)
{
if (isSpecial)
{
_logger.Debug("Special, skipping sample check");
return DetectSampleResult.NotSample;
}
var extension = Path.GetExtension(path);
if (extension != null)
@ -73,11 +67,11 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
if (runTime.Value.TotalSeconds < minimumRuntime)
{
_logger.Debug("[{0}] appears to be a sample. Runtime: {1} seconds. Expected at least: {2} seconds", path, runTime, minimumRuntime);
_logger.Debug("[{0}] appears to be a sample. Runtime: {1} seconds. Expected at least: {2} seconds", path, runTime.Value.TotalSeconds, minimumRuntime);
return DetectSampleResult.Sample;
}
_logger.Debug("Runtime is over 90 seconds");
_logger.Debug("Runtime of {0} is more than {1} seconds, Not Sample", runTime.Value.TotalSeconds, minimumRuntime);
return DetectSampleResult.NotSample;
}

@ -71,7 +71,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
downloadClientItemInfo = _parsingService.EnhanceMovieInfo(downloadClientItemInfo);
}
var nonSampleVideoFileCount = GetNonSampleVideoFileCount(newFiles, movie, downloadClientItemInfo, folderInfo);
var nonSampleVideoFileCount = GetNonSampleVideoFileCount(newFiles, movie);
var decisions = new List<ImportDecision>();
@ -180,11 +180,11 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
return null;
}
private int GetNonSampleVideoFileCount(List<string> videoFiles, Movie movie, ParsedMovieInfo downloadClientItemInfo, ParsedMovieInfo folderInfo)
private int GetNonSampleVideoFileCount(List<string> videoFiles, Movie movie)
{
return videoFiles.Count(file =>
{
var sample = _detectSample.IsSample(movie, file, false);
var sample = _detectSample.IsSample(movie, file);
if (sample == DetectSampleResult.Sample)
{

@ -19,14 +19,22 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Specifications
public Decision IsSatisfiedBy(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{
var sample = _detectSample.IsSample(localMovie.Movie,
localMovie.Path,
false);
if (localMovie.ExistingFile)
{
_logger.Debug("Existing file, skipping sample check");
return Decision.Accept();
}
var sample = _detectSample.IsSample(localMovie.Movie, localMovie.Path);
if (sample == DetectSampleResult.Sample)
{
return Decision.Reject("Sample");
}
else if (sample == DetectSampleResult.Indeterminate)
{
return Decision.Reject("Unable to determine if file is a sample");
}
return Decision.Accept();
}

Loading…
Cancel
Save