ec1f5dc317
Add Argument*Exceptions now use proper nameof operators. Added exception messages to quite a few Argument*Exceptions. Fixed rethorwing to be proper syntax. Added a ton of null checkes. (This is only a start, there are about 500 places that need proper null handling) Added some TODOs to log certain exceptions. Fix sln again. Fixed all AssemblyInfo's and added proper copyright (where I could find them) We live in *current year*. Fixed the use of braces. Fixed a ton of properties, and made a fair amount of functions static that should be and can be static. Made more Methods that should be static static. You can now use static to find bad functions! Removed unused variable. And added one more proper XML comment.
118 lines
3.6 KiB
C#
118 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace MediaBrowser.MediaEncoding.Probing
|
|
{
|
|
public static class FFProbeHelpers
|
|
{
|
|
/// <summary>
|
|
/// Normalizes the FF probe result.
|
|
/// </summary>
|
|
/// <param name="result">The result.</param>
|
|
public static void NormalizeFFProbeResult(InternalMediaInfoResult result)
|
|
{
|
|
if (result == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a string from an FFProbeResult tags dictionary
|
|
/// </summary>
|
|
/// <param name="tags">The tags.</param>
|
|
/// <param name="key">The key.</param>
|
|
/// <returns>System.String.</returns>
|
|
public static string GetDictionaryValue(Dictionary<string, string> tags, string key)
|
|
{
|
|
if (tags == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
string val;
|
|
|
|
tags.TryGetValue(key, out val);
|
|
return val;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets an int from an FFProbeResult tags dictionary
|
|
/// </summary>
|
|
/// <param name="tags">The tags.</param>
|
|
/// <param name="key">The key.</param>
|
|
/// <returns>System.Nullable{System.Int32}.</returns>
|
|
public static int? GetDictionaryNumericValue(Dictionary<string, string> tags, string key)
|
|
{
|
|
var val = GetDictionaryValue(tags, key);
|
|
|
|
if (!string.IsNullOrEmpty(val))
|
|
{
|
|
int i;
|
|
|
|
if (int.TryParse(val, out i))
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a DateTime from an FFProbeResult tags dictionary
|
|
/// </summary>
|
|
/// <param name="tags">The tags.</param>
|
|
/// <param name="key">The key.</param>
|
|
/// <returns>System.Nullable{DateTime}.</returns>
|
|
public static DateTime? GetDictionaryDateTime(Dictionary<string, string> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a dictionary to case insensitive
|
|
/// </summary>
|
|
/// <param name="dict">The dict.</param>
|
|
/// <returns>Dictionary{System.StringSystem.String}.</returns>
|
|
private static Dictionary<string, string> ConvertDictionaryToCaseInSensitive(Dictionary<string, string> dict)
|
|
{
|
|
return new Dictionary<string, string>(dict, StringComparer.OrdinalIgnoreCase);
|
|
}
|
|
}
|
|
}
|