From f20856411e28f852c376db96e25d573113771bc0 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Fri, 28 Jul 2023 07:16:45 +0200 Subject: [PATCH] Fix format normalizer for multiple input formats --- .../Probing/ProbeResultNormalizer.cs | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 7d655240b7..aeb08cea35 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -1,5 +1,4 @@ #nullable disable -#pragma warning disable CS1591 using System; using System.Collections.Generic; @@ -20,6 +19,9 @@ using Microsoft.Extensions.Logging; namespace MediaBrowser.MediaEncoding.Probing { + /// + /// Class responsible for normalizing FFprobe output. + /// public class ProbeResultNormalizer { // When extracting subtitles, the maximum length to consider (to avoid invalid filenames) @@ -36,6 +38,11 @@ namespace MediaBrowser.MediaEncoding.Probing private string[] _splitWhiteList; + /// + /// Initializes a new instance of the class. + /// + /// The for use with the instance. + /// The for use with the instance. public ProbeResultNormalizer(ILogger logger, ILocalizationManager localization) { _logger = logger; @@ -73,6 +80,15 @@ namespace MediaBrowser.MediaEncoding.Probing "Smith/Kotzen", }; + /// + /// Transforms a FFprobe response into its equivalent. + /// + /// The . + /// The . + /// A boolean indicating whether the media is audio. + /// Path to media file. + /// Path media protocol. + /// The . public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType? videoType, bool isAudio, string path, MediaProtocol protocol) { var info = new MediaInfo @@ -252,25 +268,30 @@ namespace MediaBrowser.MediaEncoding.Probing return null; } - // Handle MPEG-1 container - if (string.Equals(format, "mpegvideo", StringComparison.OrdinalIgnoreCase)) + // Input can be a list of multiple, comma-delimited formats - each of them needs to be checked + var splitFormat = format.Split(','); + for (var i = 0; i < splitFormat.Length; i++) { - return "mpeg"; - } + // Handle MPEG-1 container + if (string.Equals(splitFormat[i], "mpegvideo", StringComparison.OrdinalIgnoreCase)) + { + splitFormat[i] = "mpeg"; + } - // Handle MPEG-2 container - if (string.Equals(format, "mpeg", StringComparison.OrdinalIgnoreCase)) - { - return "ts"; - } + // Handle MPEG-2 container + else if (string.Equals(splitFormat[i], "mpeg", StringComparison.OrdinalIgnoreCase)) + { + splitFormat[i] = "ts"; + } - // Handle matroska container - if (string.Equals(format, "matroska", StringComparison.OrdinalIgnoreCase)) - { - return "mkv"; + // Handle matroska container + else if (string.Equals(splitFormat[i], "matroska", StringComparison.OrdinalIgnoreCase)) + { + splitFormat[i] = "mkv"; + } } - return format; + return string.Join(',', splitFormat); } private int? GetEstimatedAudioBitrate(string codec, int? channels)