1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

New: Reject File if Sample Check Indeterminate

This commit is contained in:
Qstick 2020-07-19 01:45:23 -04:00
parent 1c85bd96f8
commit 2390ab98fa
6 changed files with 26 additions and 31 deletions

View File

@ -256,8 +256,7 @@ public void should_delete_folder_if_files_were_imported_and_only_sample_files_re
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 @@ public void should_not_delete_if_there_is_large_rar_file()
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 @@ public void should_not_delete_if_no_files_were_imported()
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>()

View File

@ -97,8 +97,7 @@ public void should_use_runtime()
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 @@ public void should_return_indeterminate_if_mediainfo_result_is_null()
.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 @@ public void should_return_indeterminate_if_mediainfo_result_is_null()
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);
} }
} }
} }

View File

@ -131,7 +131,7 @@ public bool ShouldDeleteFolder(DirectoryInfo directoryInfo, Movie movie)
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;

View File

@ -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 @@ public DetectSample(IVideoFileInfoReader videoFileInfoReader, Logger logger)
_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 @@ public DetectSampleResult IsSample(Movie movie, string path, bool isSpecial)
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;
} }

View File

@ -71,7 +71,7 @@ public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Movie mo
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 @@ private Rejection EvaluateSpec(IImportDecisionEngineSpecification spec, LocalMov
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)
{ {

View File

@ -19,14 +19,22 @@ public NotSampleSpecification(IDetectSample detectSample,
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();
} }