Files
pgsql-jellyfin/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs
T
wjones af1152b001 Refactor: standardize namespace and using directive style
Refactored all C# test files to use explicit namespace declarations and moved all using directives inside the namespace block for consistency. Updated assembly info and cache files to reflect the new build. Adjusted MvcTestingAppManifest.json to use fully qualified assembly names. No functional changes; all updates are related to code style, organization, and project metadata.
2026-02-20 16:26:53 -05:00

87 lines
3.1 KiB
C#

// <copyright file="FFProbeHelpers.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace MediaBrowser.MediaEncoding.Probing
{
using System;
using System.Collections.Generic;
using System.Globalization;
/// <summary>
/// Class containing helper methods for working with FFprobe output.
/// </summary>
public static class FFProbeHelpers
{
/// <summary>
/// Normalizes the FF probe result.
/// </summary>
/// <param name="result">The result.</param>
public static void NormalizeFFProbeResult(InternalMediaInfoResult result)
{
ArgumentNullException.ThrowIfNull(result);
if (result.Format?.Tags is not null)
{
result.Format.Tags = ConvertDictionaryToCaseInsensitive(result.Format.Tags);
}
if (result.Streams is not null)
{
// Convert all dictionaries to case-insensitive
foreach (var stream in result.Streams)
{
if (stream.Tags is not null)
{
stream.Tags = ConvertDictionaryToCaseInsensitive(stream.Tags);
}
}
}
}
/// <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(IReadOnlyDictionary<string, string> tags, string key)
{
if (tags.TryGetValue(key, out var val) && int.TryParse(val, out var 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(IReadOnlyDictionary<string, string> tags, string key)
{
if (tags.TryGetValue(key, out var val)
&& (DateTime.TryParse(val, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out var dateTime)
|| DateTime.TryParseExact(val, "yyyy", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out dateTime)))
{
return dateTime;
}
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(IReadOnlyDictionary<string, string> dict)
{
return new Dictionary<string, string>(dict, StringComparer.OrdinalIgnoreCase);
}
}
}