< Summary - Jellyfin

Information
Class: MediaBrowser.MediaEncoding.Probing.FFProbeHelpers
Assembly: MediaBrowser.MediaEncoding
File(s): /srv/git/jellyfin/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 82
Line coverage: 100%
Branch coverage
100%
Covered branches: 20
Total branches: 20
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
NormalizeFFProbeResult(...)100%1010100%
GetDictionaryNumericValue(...)100%44100%
GetDictionaryDateTime(...)100%66100%
ConvertDictionaryToCaseInsensitive(...)100%11100%

File(s)

/srv/git/jellyfin/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Globalization;
 4
 5namespace MediaBrowser.MediaEncoding.Probing
 6{
 7    /// <summary>
 8    /// Class containing helper methods for working with FFprobe output.
 9    /// </summary>
 10    public static class FFProbeHelpers
 11    {
 12        /// <summary>
 13        /// Normalizes the FF probe result.
 14        /// </summary>
 15        /// <param name="result">The result.</param>
 16        public static void NormalizeFFProbeResult(InternalMediaInfoResult result)
 17        {
 1018            ArgumentNullException.ThrowIfNull(result);
 19
 1020            if (result.Format?.Tags is not null)
 21            {
 722                result.Format.Tags = ConvertDictionaryToCaseInsensitive(result.Format.Tags);
 23            }
 24
 1025            if (result.Streams is not null)
 26            {
 27                // Convert all dictionaries to case insensitive
 6628                foreach (var stream in result.Streams)
 29                {
 2330                    if (stream.Tags is not null)
 31                    {
 1932                        stream.Tags = ConvertDictionaryToCaseInsensitive(stream.Tags);
 33                    }
 34                }
 35            }
 1036        }
 37
 38        /// <summary>
 39        /// Gets an int from an FFProbeResult tags dictionary.
 40        /// </summary>
 41        /// <param name="tags">The tags.</param>
 42        /// <param name="key">The key.</param>
 43        /// <returns>System.Nullable{System.Int32}.</returns>
 44        public static int? GetDictionaryNumericValue(IReadOnlyDictionary<string, string> tags, string key)
 45        {
 3046            if (tags.TryGetValue(key, out var val) && int.TryParse(val, out var i))
 47            {
 248                return i;
 49            }
 50
 2851            return null;
 52        }
 53
 54        /// <summary>
 55        /// Gets a DateTime from an FFProbeResult tags dictionary.
 56        /// </summary>
 57        /// <param name="tags">The tags.</param>
 58        /// <param name="key">The key.</param>
 59        /// <returns>System.Nullable{DateTime}.</returns>
 60        public static DateTime? GetDictionaryDateTime(IReadOnlyDictionary<string, string> tags, string key)
 61        {
 5662            if (tags.TryGetValue(key, out var val)
 5663                && (DateTime.TryParse(val, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal | DateTimeStyl
 5664                    || DateTime.TryParseExact(val, "yyyy", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversa
 65            {
 566                return dateTime;
 67            }
 68
 5169            return null;
 70        }
 71
 72        /// <summary>
 73        /// Converts a dictionary to case insensitive.
 74        /// </summary>
 75        /// <param name="dict">The dict.</param>
 76        /// <returns>Dictionary{System.StringSystem.String}.</returns>
 77        private static Dictionary<string, string> ConvertDictionaryToCaseInsensitive(IReadOnlyDictionary<string, string>
 78        {
 2679            return new Dictionary<string, string>(dict, StringComparer.OrdinalIgnoreCase);
 80        }
 81    }
 82}