1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-22 22:15:17 -04:00

New: Use MediaInfo on File Parsing

This commit is contained in:
Qstick
2019-07-15 22:27:35 -04:00
parent ada9b944dc
commit bfc467dd96
51 changed files with 1092 additions and 689 deletions
@@ -1,17 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using NLog;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Movies;
namespace NzbDrone.Core.MediaFiles.MovieImport
{
public interface IDetectSample
{
bool IsSample(Movie movie, QualityModel quality, string path, long size, bool isSpecial);
DetectSampleResult IsSample(Movie movie, string path, bool isSpecial);
}
public class DetectSample : IDetectSample
@@ -19,23 +16,18 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
private readonly IVideoFileInfoReader _videoFileInfoReader;
private readonly Logger _logger;
//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};
public DetectSample(IVideoFileInfoReader videoFileInfoReader, Logger logger)
{
_videoFileInfoReader = videoFileInfoReader;
_logger = logger;
}
public static long SampleSizeLimit => 70.Megabytes();
public bool IsSample(Movie movie, QualityModel quality, string path, long size, bool isSpecial)
public DetectSampleResult IsSample(Movie movie, string path, bool isSpecial)
{
if (isSpecial)
{
_logger.Debug("Special, skipping sample check");
return false;
return DetectSampleResult.NotSample;
}
var extension = Path.GetExtension(path);
@@ -43,72 +35,64 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
if (extension != null && extension.Equals(".flv", StringComparison.InvariantCultureIgnoreCase))
{
_logger.Debug("Skipping sample check for .flv file");
return false;
return DetectSampleResult.NotSample;
}
if (extension != null && extension.Equals(".strm", StringComparison.InvariantCultureIgnoreCase))
{
_logger.Debug("Skipping sample check for .strm file");
return false;
return DetectSampleResult.NotSample;
}
try
// TODO: Use MediaInfo from the import process, no need to re-process the file again here
var runTime = _videoFileInfoReader.GetRunTime(path);
if (!runTime.HasValue)
{
var runTime = _videoFileInfoReader.GetRunTime(path);
var minimumRuntime = GetMinimumAllowedRuntime(movie);
if (runTime.Value.TotalMinutes.Equals(0))
{
_logger.Error("[{0}] has a runtime of 0, is it a valid video file?", path);
return true;
}
if (runTime.Value.TotalSeconds < minimumRuntime)
{
_logger.Debug("[{0}] appears to be a sample. Runtime: {1} seconds. Expected at least: {2} seconds", path, runTime, minimumRuntime);
return true;
}
_logger.Error("Failed to get runtime from the file, make sure mediainfo is available");
return DetectSampleResult.Indeterminate;
}
catch (DllNotFoundException)
{
_logger.Debug("Falling back to file size detection");
var minimumRuntime = GetMinimumAllowedRuntime(movie);
return CheckSize(size, quality);
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 (runTime.Value.TotalSeconds < 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("Runtime is over 90 seconds");
return false;
}
private bool CheckSize(long size, QualityModel quality)
{
if (_largeSampleSizeResolutions.Contains(quality.Resolution))
{
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;
return DetectSampleResult.NotSample;
}
private int GetMinimumAllowedRuntime(Movie movie)
{
if (movie.Runtime < 1)
//Anime short - 15 seconds
if (movie.Runtime <= 3)
{
return 5 * 60;
return 15;
}
return movie.Runtime / 5 * 60;
//Webisodes - 90 seconds
if (movie.Runtime <= 10)
{
return 90;
}
//30 minute episodes - 5 minutes
if (movie.Runtime <= 30)
{
return 300;
}
//60 minute episodes - 10 minutes
return 600;
}
}
}