New: Reject File if Sample Check Indeterminate

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

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

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

@ -131,7 +131,7 @@ namespace NzbDrone.Core.MediaFiles
return false; 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); _logger.Warn("Non-sample file detected: [{0}]", videoFile);
return false; return false;

@ -9,7 +9,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
{ {
public interface IDetectSample public interface IDetectSample
{ {
DetectSampleResult IsSample(Movie movie, string path, bool isSpecial); DetectSampleResult IsSample(Movie movie, string path);
} }
public class DetectSample : IDetectSample public class DetectSample : IDetectSample
@ -23,14 +23,8 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
_logger = logger; _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); var extension = Path.GetExtension(path);
if (extension != null) if (extension != null)
@ -73,11 +67,11 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
if (runTime.Value.TotalSeconds < minimumRuntime) 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; 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; return DetectSampleResult.NotSample;
} }

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

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

Loading…
Cancel
Save