From 1d7d52ff9e42c3efb4bb2c65e82a4a82faf9decb Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Fri, 14 Dec 2018 10:40:55 +0100 Subject: Port MediaEncoding and Api.Playback from 10e57ce8d21b4516733894075001819f3cd6db6b --- .../Probing/FFProbeHelpers.cs | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs (limited to 'MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs') diff --git a/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs b/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs new file mode 100644 index 000000000..396c85e21 --- /dev/null +++ b/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; + +namespace MediaBrowser.MediaEncoding.Probing +{ + public static class FFProbeHelpers + { + /// + /// Normalizes the FF probe result. + /// + /// The result. + public static void NormalizeFFProbeResult(InternalMediaInfoResult result) + { + if (result == null) + { + throw new ArgumentNullException("result"); + } + + if (result.format != null && result.format.tags != null) + { + result.format.tags = ConvertDictionaryToCaseInSensitive(result.format.tags); + } + + if (result.streams != null) + { + // Convert all dictionaries to case insensitive + foreach (var stream in result.streams) + { + if (stream.tags != null) + { + stream.tags = ConvertDictionaryToCaseInSensitive(stream.tags); + } + + if (stream.disposition != null) + { + stream.disposition = ConvertDictionaryToCaseInSensitive(stream.disposition); + } + } + } + } + + /// + /// Gets a string from an FFProbeResult tags dictionary + /// + /// The tags. + /// The key. + /// System.String. + public static string GetDictionaryValue(Dictionary tags, string key) + { + if (tags == null) + { + return null; + } + + string val; + + tags.TryGetValue(key, out val); + return val; + } + + /// + /// Gets an int from an FFProbeResult tags dictionary + /// + /// The tags. + /// The key. + /// System.Nullable{System.Int32}. + public static int? GetDictionaryNumericValue(Dictionary tags, string key) + { + var val = GetDictionaryValue(tags, key); + + if (!string.IsNullOrEmpty(val)) + { + int i; + + if (int.TryParse(val, out i)) + { + return i; + } + } + + return null; + } + + /// + /// Gets a DateTime from an FFProbeResult tags dictionary + /// + /// The tags. + /// The key. + /// System.Nullable{DateTime}. + public static DateTime? GetDictionaryDateTime(Dictionary tags, string key) + { + var val = GetDictionaryValue(tags, key); + + if (!string.IsNullOrEmpty(val)) + { + DateTime i; + + if (DateTime.TryParse(val, out i)) + { + return i.ToUniversalTime(); + } + } + + return null; + } + + /// + /// Converts a dictionary to case insensitive + /// + /// The dict. + /// Dictionary{System.StringSystem.String}. + private static Dictionary ConvertDictionaryToCaseInSensitive(Dictionary dict) + { + return new Dictionary(dict, StringComparer.OrdinalIgnoreCase); + } + } +} -- cgit v1.2.3