1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Updated a few harder to detect MediaInfo VideoCodec formats.

This commit is contained in:
Taloth Saldono 2018-04-18 22:07:38 +02:00
parent 5b627a8bc2
commit 1b0647423d
2 changed files with 51 additions and 12 deletions

View File

@ -15,7 +15,7 @@ public class FormatVideoCodecFixture : TestBase
[TestCase("V_MPEGH/ISO/HEVC", "source.title.x265.720p-Sonarr", "x265")] [TestCase("V_MPEGH/ISO/HEVC", "source.title.x265.720p-Sonarr", "x265")]
[TestCase("V_MPEGH/ISO/HEVC", "source.title.h265.720p-Sonarr", "h265")] [TestCase("V_MPEGH/ISO/HEVC", "source.title.h265.720p-Sonarr", "h265")]
[TestCase("MPEG-2 Video", null, "MPEG2")] [TestCase("MPEG-2 Video", null, "MPEG2")]
public void should_format_video_codec_with_source_title(string videoCodec, string sceneName, string expectedFormat) public void should_format_video_codec_with_source_title_legacy(string videoCodec, string sceneName, string expectedFormat)
{ {
var mediaInfoModel = new MediaInfoModel var mediaInfoModel = new MediaInfoModel
{ {
@ -39,6 +39,11 @@ public void should_format_video_codec_with_source_title(string videoCodec, strin
[TestCase("VP7, VP70, General, ", "Sweet Seymour.avi", "VP7")] [TestCase("VP7, VP70, General, ", "Sweet Seymour.avi", "VP7")]
[TestCase("VP8, V_VP8, , ", "Dick.mkv", "VP8")] [TestCase("VP8, V_VP8, , ", "Dick.mkv", "VP8")]
[TestCase("VP9, V_VP9, , ", "Roadkill Ep3x11 - YouTube.webm", "VP9")] [TestCase("VP9, V_VP9, , ", "Roadkill Ep3x11 - YouTube.webm", "VP9")]
[TestCase("x264, x264, , ", "Ghost Advent - S04E05 - Stanley Hotel SDTV.avi", "x264")]
[TestCase("V_MPEGH/ISO/HEVC, V_MPEGH/ISO/HEVC, , ", "The BBT S11E12 The Matrimonial Metric 1080p 10bit AMZN WEB-DL", "h265")]
[TestCase("MPEG-4 Visual, 20, Simple@L1, Lavc52.29.0", "Will.And.Grace.S08E14.WS.DVDrip.XviD.I.Love.L.Gay-Obfuscated", "XviD")]
[TestCase("MPEG-4 Visual, 20, Advanced Simple@L5, XviD0046", "", "XviD")]
[TestCase("mp4v, mp4v, , ", "American.Chopper.S06E07.Mountain.Creek.Bike.DSR.XviD-KRS", "XviD")]
public void should_format_video_format(string videoFormatPack, string sceneName, string expectedFormat) public void should_format_video_format(string videoFormatPack, string sceneName, string expectedFormat)
{ {
var split = videoFormatPack.Split(new string[] { ", " }, System.StringSplitOptions.None); var split = videoFormatPack.Split(new string[] { ", " }, System.StringSplitOptions.None);
@ -53,6 +58,22 @@ public void should_format_video_format(string videoFormatPack, string sceneName,
MediaInfoFormatter.FormatVideoCodec(mediaInfoModel, sceneName).Should().Be(expectedFormat); MediaInfoFormatter.FormatVideoCodec(mediaInfoModel, sceneName).Should().Be(expectedFormat);
} }
[TestCase("MPEG-4 Visual, 20, , Intel(R) MPEG-4 encoder based on Intel(R) IPP 6.1 build 137.20[6.1.137.763]", "", "")]
public void should_warn_on_unknown_video_format(string videoFormatPack, string sceneName, string expectedFormat)
{
var split = videoFormatPack.Split(new string[] { ", " }, System.StringSplitOptions.None);
var mediaInfoModel = new MediaInfoModel
{
VideoFormat = split[0],
VideoCodecID = split[1],
VideoProfile = split[2],
VideoCodecLibrary = split[3]
};
MediaInfoFormatter.FormatVideoCodec(mediaInfoModel, sceneName).Should().Be(expectedFormat);
ExceptionVerification.ExpectedWarns(1);
}
[Test] [Test]
public void should_return_VideoFormat_by_default() public void should_return_VideoFormat_by_default()
{ {

View File

@ -199,9 +199,16 @@ public static string FormatVideoCodec(MediaInfoModel mediaInfo, string sceneName
var videoProfile = mediaInfo.VideoProfile ?? string.Empty; var videoProfile = mediaInfo.VideoProfile ?? string.Empty;
var videoCodecLibrary = mediaInfo.VideoCodecLibrary ?? string.Empty; var videoCodecLibrary = mediaInfo.VideoCodecLibrary ?? string.Empty;
var result = videoFormat;
if (videoFormat.IsNullOrWhiteSpace()) if (videoFormat.IsNullOrWhiteSpace())
{ {
return videoFormat; return result;
}
if (videoFormat == "x264")
{
return "x264";
} }
if (videoFormat == "AVC" || videoFormat == "V.MPEG4/ISO/AVC") if (videoFormat == "AVC" || videoFormat == "V.MPEG4/ISO/AVC")
@ -214,12 +221,7 @@ public static string FormatVideoCodec(MediaInfoModel mediaInfo, string sceneName
return GetSceneNameMatch(sceneName, "AVC", "h264"); return GetSceneNameMatch(sceneName, "AVC", "h264");
} }
if (videoFormat.EqualsIgnoreCase("DivX") || videoFormat.EqualsIgnoreCase("div3")) if (videoFormat == "HEVC" || videoFormat == "V_MPEGH/ISO/HEVC")
{
return "DivX";
}
if (videoFormat == "HEVC")
{ {
if (videoCodecLibrary.StartsWithIgnoreCase("x265")) if (videoCodecLibrary.StartsWithIgnoreCase("x265"))
{ {
@ -249,19 +251,30 @@ public static string FormatVideoCodec(MediaInfoModel mediaInfo, string sceneName
if (videoFormat == "MPEG-4 Visual") if (videoFormat == "MPEG-4 Visual")
{ {
if (videoCodecID.ContainsIgnoreCase("XVID")) if (videoCodecID.ContainsIgnoreCase("XVID") ||
videoCodecLibrary.StartsWithIgnoreCase("XviD"))
{ {
return "XviD"; return "XviD";
} }
if (videoCodecID.ContainsIgnoreCase("DIV3") || if (videoCodecID.ContainsIgnoreCase("DIV3") ||
videoCodecID.ContainsIgnoreCase("DIVX") || videoCodecID.ContainsIgnoreCase("DIVX") ||
videoCodecID.ContainsIgnoreCase("DX50")) videoCodecID.ContainsIgnoreCase("DX50") ||
videoCodecLibrary.StartsWithIgnoreCase("DivX"))
{ {
return "DivX"; return "DivX";
} }
} }
if (videoFormat == "MPEG-4 Visual" || videoFormat == "mp4v")
{
result = GetSceneNameMatch(sceneName, "XviD", "DivX", "");
if (result.IsNotNullOrWhiteSpace())
{
return result;
}
}
if (videoFormat == "VC-1") if (videoFormat == "VC-1")
{ {
return "VC1"; return "VC1";
@ -278,6 +291,11 @@ public static string FormatVideoCodec(MediaInfoModel mediaInfo, string sceneName
return "WMV"; return "WMV";
} }
if (videoFormat.EqualsIgnoreCase("DivX") || videoFormat.EqualsIgnoreCase("div3"))
{
return "DivX";
}
if (videoFormat.EqualsIgnoreCase("XviD")) if (videoFormat.EqualsIgnoreCase("XviD"))
{ {
return "XviD"; return "XviD";
@ -288,7 +306,7 @@ public static string FormatVideoCodec(MediaInfoModel mediaInfo, string sceneName
.WriteSentryWarn("UnknownVideoFormat", mediaInfo.ContainerFormat, videoFormat, videoCodecID) .WriteSentryWarn("UnknownVideoFormat", mediaInfo.ContainerFormat, videoFormat, videoCodecID)
.Write(); .Write();
return videoFormat; return result;
} }
public static string FormatVideoCodecLegacy(MediaInfoModel mediaInfo, string sceneName) public static string FormatVideoCodecLegacy(MediaInfoModel mediaInfo, string sceneName)
@ -413,7 +431,7 @@ public static string FormatVideoCodecLegacy(MediaInfoModel mediaInfo, string sce
private static string GetSceneNameMatch(string sceneName, params string[] tokens) private static string GetSceneNameMatch(string sceneName, params string[] tokens)
{ {
sceneName = sceneName.IsNotNullOrWhiteSpace() ? Path.GetFileNameWithoutExtension(sceneName) : string.Empty; sceneName = sceneName.IsNotNullOrWhiteSpace() ? Parser.Parser.RemoveFileExtension(sceneName) : string.Empty;
foreach (var token in tokens) foreach (var token in tokens)
{ {