ConfigurationExtensions.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using Microsoft.Extensions.Configuration;
  3. namespace MediaBrowser.Controller.Extensions
  4. {
  5. /// <summary>
  6. /// Configuration extensions for <c>MediaBrowser.Controller</c>.
  7. /// </summary>
  8. public static class ConfigurationExtensions
  9. {
  10. /// <summary>
  11. /// The key for a setting that indicates whether the application should host web client content.
  12. /// </summary>
  13. public const string HostWebClientKey = "hostwebclient";
  14. /// <summary>
  15. /// The key for the FFmpeg probe size option.
  16. /// </summary>
  17. public const string FfmpegProbeSizeKey = "FFmpeg:probesize";
  18. /// <summary>
  19. /// The key for the FFmpeg analyze duration option.
  20. /// </summary>
  21. public const string FfmpegAnalyzeDurationKey = "FFmpeg:analyzeduration";
  22. /// <summary>
  23. /// The key for a setting that indicates whether playlists should allow duplicate entries.
  24. /// </summary>
  25. public const string PlaylistsAllowDuplicatesKey = "playlists:allowDuplicates";
  26. /// <summary>
  27. /// Gets a value indicating whether the application should host static web content from the <see cref="IConfiguration"/>.
  28. /// </summary>
  29. /// <param name="configuration">The configuration to retrieve the value from.</param>
  30. /// <returns>The parsed config value.</returns>
  31. /// <exception cref="FormatException">The config value is not a valid bool string. See <see cref="bool.Parse(string)"/>.</exception>
  32. public static bool HostWebClient(this IConfiguration configuration)
  33. => configuration.GetValue<bool>(HostWebClientKey);
  34. /// <summary>
  35. /// Gets the FFmpeg probe size from the <see cref="IConfiguration" />.
  36. /// </summary>
  37. /// <param name="configuration">The configuration to read the setting from.</param>
  38. /// <returns>The FFmpeg probe size option.</returns>
  39. public static string GetFFmpegProbeSize(this IConfiguration configuration)
  40. => configuration[FfmpegProbeSizeKey];
  41. /// <summary>
  42. /// Gets the FFmpeg analyze duration from the <see cref="IConfiguration" />.
  43. /// </summary>
  44. /// <param name="configuration">The configuration to read the setting from.</param>
  45. /// <returns>The FFmpeg analyze duration option.</returns>
  46. public static string GetFFmpegAnalyzeDuration(this IConfiguration configuration)
  47. => configuration[FfmpegAnalyzeDurationKey];
  48. /// <summary>
  49. /// Gets a value indicating whether playlists should allow duplicate entries from the <see cref="IConfiguration"/>.
  50. /// </summary>
  51. /// <param name="configuration">The configuration to read the setting from.</param>
  52. /// <returns>True if playlists should allow duplicates, otherwise false.</returns>
  53. public static bool DoPlaylistsAllowDuplicates(this IConfiguration configuration)
  54. => configuration.GetValue<bool>(PlaylistsAllowDuplicatesKey);
  55. }
  56. }