using System; using Microsoft.Extensions.Configuration; namespace MediaBrowser.Controller.Extensions { /// /// Configuration extensions for MediaBrowser.Controller. /// public static class ConfigurationExtensions { /// /// The key for a setting that indicates whether the application should host static web content. /// public const string NoWebContentKey = "nowebcontent"; /// /// The key for the FFmpeg probe size option. /// public const string FfmpegProbeSizeKey = "FFmpeg:probesize"; /// /// The key for the FFmpeg analyse duration option. /// public const string FfmpegAnalyzeDurationKey = "FFmpeg:analyzeduration"; /// /// Retrieves a config value indicating whether the application should not host /// static web content from the . /// /// The configuration to retrieve the value from. /// The parsed config value. /// The config value is not a valid bool string. See . public static bool IsNoWebContent(this IConfiguration configuration) => configuration.ParseBoolean(NoWebContentKey); /// /// Retrieves the FFmpeg probe size from the . /// /// This configuration. /// The FFmpeg probe size option. public static string GetFFmpegProbeSize(this IConfiguration configuration) => configuration[FfmpegProbeSizeKey]; /// /// Retrieves the FFmpeg analyse duration from the . /// /// This configuration. /// The FFmpeg analyse duration option. public static string GetFFmpegAnalyzeDuration(this IConfiguration configuration) => configuration[FfmpegAnalyzeDurationKey]; /// /// Convert the specified configuration string value its equivalent. /// /// The configuration to retrieve and parse the setting from. /// The key to use to retrieve the string value from the configuration. /// The parsed boolean value. /// The config value is not a valid bool string. See . public static bool ParseBoolean(this IConfiguration configuration, string key) { string configValue = configuration[key]; return bool.TryParse(configValue, out bool result) ? result : throw new FormatException($"Invalid value for configuration option '{key}' (expected a boolean): {configValue}"); } } }