aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs')
-rw-r--r--MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs69
1 files changed, 47 insertions, 22 deletions
diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
index 7d655240b..be1e8a172 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,7 +19,10 @@ using Microsoft.Extensions.Logging;
namespace MediaBrowser.MediaEncoding.Probing
{
- public class ProbeResultNormalizer
+ /// <summary>
+ /// Class responsible for normalizing FFprobe output.
+ /// </summary>
+ public partial class ProbeResultNormalizer
{
// When extracting subtitles, the maximum length to consider (to avoid invalid filenames)
private const int MaxSubtitleDescriptionExtractionLength = 100;
@@ -29,13 +31,16 @@ namespace MediaBrowser.MediaEncoding.Probing
private readonly char[] _nameDelimiters = { '/', '|', ';', '\\' };
- private static readonly Regex _performerPattern = new(@"(?<name>.*) \((?<instrument>.*)\)");
-
private readonly ILogger _logger;
private readonly ILocalizationManager _localization;
private string[] _splitWhiteList;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ProbeResultNormalizer"/> class.
+ /// </summary>
+ /// <param name="logger">The <see cref="ILogger{ProbeResultNormalizer}"/> for use with the <see cref="ProbeResultNormalizer"/> instance.</param>
+ /// <param name="localization">The <see cref="ILocalizationManager"/> for use with the <see cref="ProbeResultNormalizer"/> instance.</param>
public ProbeResultNormalizer(ILogger logger, ILocalizationManager localization)
{
_logger = logger;
@@ -71,8 +76,18 @@ namespace MediaBrowser.MediaEncoding.Probing
"She/Her/Hers",
"5/8erl in Ehr'n",
"Smith/Kotzen",
+ "We;Na",
};
+ /// <summary>
+ /// Transforms a FFprobe response into its <see cref="MediaInfo"/> equivalent.
+ /// </summary>
+ /// <param name="data">The <see cref="InternalMediaInfoResult"/>.</param>
+ /// <param name="videoType">The <see cref="VideoType"/>.</param>
+ /// <param name="isAudio">A boolean indicating whether the media is audio.</param>
+ /// <param name="path">Path to media file.</param>
+ /// <param name="protocol">Path media protocol.</param>
+ /// <returns>The <see cref="MediaInfo"/>.</returns>
public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType? videoType, bool isAudio, string path, MediaProtocol protocol)
{
var info = new MediaInfo
@@ -252,25 +267,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)
@@ -741,9 +761,11 @@ namespace MediaBrowser.MediaEncoding.Probing
&& !string.Equals(streamInfo.FieldOrder, "progressive", StringComparison.OrdinalIgnoreCase);
if (isAudio
- || string.Equals(stream.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase)
- || string.Equals(stream.Codec, "gif", StringComparison.OrdinalIgnoreCase)
- || string.Equals(stream.Codec, "png", StringComparison.OrdinalIgnoreCase))
+ && (string.Equals(stream.Codec, "bmp", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(stream.Codec, "gif", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(stream.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(stream.Codec, "png", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(stream.Codec, "webp", StringComparison.OrdinalIgnoreCase)))
{
stream.Type = MediaStreamType.EmbeddedImage;
}
@@ -1191,7 +1213,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
foreach (var person in Split(performer, false))
{
- Match match = _performerPattern.Match(person);
+ Match match = PerformerRegex().Match(person);
// If the performer doesn't have any instrument/role associated, it won't match. In that case, chances are it's simply a band name, so we skip it.
if (match.Success)
@@ -1630,5 +1652,8 @@ namespace MediaBrowser.MediaEncoding.Probing
return TransportStreamTimestamp.Valid;
}
+
+ [GeneratedRegex("(?<name>.*) \\((?<instrument>.*)\\)")]
+ private static partial Regex PerformerRegex();
}
}