2018-03-14 20:41:36 +00:00
|
|
|
using System;
|
2014-04-04 00:08:51 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using NLog;
|
2018-08-05 14:28:05 +00:00
|
|
|
using NzbDrone.Core.CustomFormats;
|
2014-04-04 00:08:51 +00:00
|
|
|
using NzbDrone.Core.MediaFiles.MediaInfo;
|
|
|
|
using NzbDrone.Core.Qualities;
|
2018-03-14 20:41:36 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2014-04-04 00:08:51 +00:00
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
namespace NzbDrone.Core.MediaFiles.MovieImport
|
2014-04-04 00:08:51 +00:00
|
|
|
{
|
2015-01-27 05:57:07 +00:00
|
|
|
public interface IDetectSample
|
2014-04-04 00:08:51 +00:00
|
|
|
{
|
2017-01-03 19:24:55 +00:00
|
|
|
bool IsSample(Movie movie, QualityModel quality, string path, long size, bool isSpecial);
|
2014-04-04 00:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 05:57:07 +00:00
|
|
|
public class DetectSample : IDetectSample
|
2014-04-04 00:08:51 +00:00
|
|
|
{
|
|
|
|
private readonly IVideoFileInfoReader _videoFileInfoReader;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
//private static List<Quality> _largeSampleSizeQualities = new List<Quality> { Quality.HDTV1080p, Quality.WEBDL1080p, Quality.Bluray1080p };
|
|
|
|
private static List<Resolution> _largeSampleSizeResolutions = new List<Resolution>{Resolution.R1080P, Resolution.R2160P};
|
2014-04-04 00:08:51 +00:00
|
|
|
|
2015-01-27 05:57:07 +00:00
|
|
|
public DetectSample(IVideoFileInfoReader videoFileInfoReader, Logger logger)
|
2014-04-04 00:08:51 +00:00
|
|
|
{
|
|
|
|
_videoFileInfoReader = videoFileInfoReader;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public static long SampleSizeLimit => 70.Megabytes();
|
2014-04-04 00:08:51 +00:00
|
|
|
|
2017-01-03 19:24:55 +00:00
|
|
|
public bool IsSample(Movie movie, QualityModel quality, string path, long size, bool isSpecial)
|
|
|
|
{
|
|
|
|
if (isSpecial)
|
|
|
|
{
|
|
|
|
_logger.Debug("Special, skipping sample check");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var extension = Path.GetExtension(path);
|
|
|
|
|
|
|
|
if (extension != null && extension.Equals(".flv", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
{
|
|
|
|
_logger.Debug("Skipping sample check for .flv file");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extension != null && extension.Equals(".strm", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
{
|
|
|
|
_logger.Debug("Skipping sample check for .strm file");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var runTime = _videoFileInfoReader.GetRunTime(path);
|
|
|
|
var minimumRuntime = GetMinimumAllowedRuntime(movie);
|
|
|
|
|
2019-07-01 01:50:01 +00:00
|
|
|
if (runTime.Value.TotalMinutes.Equals(0))
|
2017-01-03 19:24:55 +00:00
|
|
|
{
|
|
|
|
_logger.Error("[{0}] has a runtime of 0, is it a valid video file?", path);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-01 01:50:01 +00:00
|
|
|
if (runTime.Value.TotalSeconds < minimumRuntime)
|
2017-01-03 19:24:55 +00:00
|
|
|
{
|
|
|
|
_logger.Debug("[{0}] appears to be a sample. Runtime: {1} seconds. Expected at least: {2} seconds", path, runTime, minimumRuntime);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (DllNotFoundException)
|
|
|
|
{
|
|
|
|
_logger.Debug("Falling back to file size detection");
|
|
|
|
|
|
|
|
return CheckSize(size, quality);
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.Debug("Runtime is over 90 seconds");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-04 00:08:51 +00:00
|
|
|
private bool CheckSize(long size, QualityModel quality)
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
if (_largeSampleSizeResolutions.Contains(quality.Resolution))
|
2014-04-04 00:08:51 +00:00
|
|
|
{
|
|
|
|
if (size < SampleSizeLimit * 2)
|
|
|
|
{
|
|
|
|
_logger.Debug("1080p file is less than sample limit");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < SampleSizeLimit)
|
|
|
|
{
|
|
|
|
_logger.Debug("File is less than sample limit");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-18 01:07:27 +00:00
|
|
|
|
2017-01-03 19:24:55 +00:00
|
|
|
private int GetMinimumAllowedRuntime(Movie movie)
|
|
|
|
{
|
2017-02-02 16:35:00 +00:00
|
|
|
if (movie.Runtime < 1)
|
|
|
|
{
|
|
|
|
return 5 * 60;
|
|
|
|
}
|
|
|
|
|
2017-02-02 17:18:02 +00:00
|
|
|
return movie.Runtime / 5 * 60;
|
2017-01-03 19:24:55 +00:00
|
|
|
}
|
2014-04-04 00:08:51 +00:00
|
|
|
}
|
|
|
|
}
|