diff --git a/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatVideoCodecFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatVideoCodecFixture.cs index 201ff11f2..5f0c167a7 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatVideoCodecFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatVideoCodecFixture.cs @@ -15,7 +15,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests [TestCase("V_MPEGH/ISO/HEVC", "source.title.x265.720p-Sonarr", "x265")] [TestCase("V_MPEGH/ISO/HEVC", "source.title.h265.720p-Sonarr", "h265")] [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 { @@ -39,6 +39,11 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests [TestCase("VP7, VP70, General, ", "Sweet Seymour.avi", "VP7")] [TestCase("VP8, V_VP8, , ", "Dick.mkv", "VP8")] [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) { var split = videoFormatPack.Split(new string[] { ", " }, System.StringSplitOptions.None); @@ -53,6 +58,22 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests 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] public void should_return_VideoFormat_by_default() { diff --git a/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs b/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs index a7fc93e5a..651b8aab0 100644 --- a/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs +++ b/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs @@ -199,9 +199,16 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo var videoProfile = mediaInfo.VideoProfile ?? string.Empty; var videoCodecLibrary = mediaInfo.VideoCodecLibrary ?? string.Empty; + var result = videoFormat; + if (videoFormat.IsNullOrWhiteSpace()) { - return videoFormat; + return result; + } + + if (videoFormat == "x264") + { + return "x264"; } if (videoFormat == "AVC" || videoFormat == "V.MPEG4/ISO/AVC") @@ -214,12 +221,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo return GetSceneNameMatch(sceneName, "AVC", "h264"); } - if (videoFormat.EqualsIgnoreCase("DivX") || videoFormat.EqualsIgnoreCase("div3")) - { - return "DivX"; - } - - if (videoFormat == "HEVC") + if (videoFormat == "HEVC" || videoFormat == "V_MPEGH/ISO/HEVC") { if (videoCodecLibrary.StartsWithIgnoreCase("x265")) { @@ -249,19 +251,30 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo if (videoFormat == "MPEG-4 Visual") { - if (videoCodecID.ContainsIgnoreCase("XVID")) + if (videoCodecID.ContainsIgnoreCase("XVID") || + videoCodecLibrary.StartsWithIgnoreCase("XviD")) { return "XviD"; } if (videoCodecID.ContainsIgnoreCase("DIV3") || videoCodecID.ContainsIgnoreCase("DIVX") || - videoCodecID.ContainsIgnoreCase("DX50")) + videoCodecID.ContainsIgnoreCase("DX50") || + videoCodecLibrary.StartsWithIgnoreCase("DivX")) { return "DivX"; } } + if (videoFormat == "MPEG-4 Visual" || videoFormat == "mp4v") + { + result = GetSceneNameMatch(sceneName, "XviD", "DivX", ""); + if (result.IsNotNullOrWhiteSpace()) + { + return result; + } + } + if (videoFormat == "VC-1") { return "VC1"; @@ -278,6 +291,11 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo return "WMV"; } + if (videoFormat.EqualsIgnoreCase("DivX") || videoFormat.EqualsIgnoreCase("div3")) + { + return "DivX"; + } + if (videoFormat.EqualsIgnoreCase("XviD")) { return "XviD"; @@ -288,7 +306,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo .WriteSentryWarn("UnknownVideoFormat", mediaInfo.ContainerFormat, videoFormat, videoCodecID) .Write(); - return videoFormat; + return result; } public static string FormatVideoCodecLegacy(MediaInfoModel mediaInfo, string sceneName) @@ -413,7 +431,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo 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) {