ConfigurationExtensions.cs 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 the FFmpeg path option.
  24. /// </summary>
  25. public const string FfmpegPathKey = "ffmpeg";
  26. /// <summary>
  27. /// The key for a setting that indicates whether playlists should allow duplicate entries.
  28. /// </summary>
  29. public const string PlaylistsAllowDuplicatesKey = "playlists:allowDuplicates";
  30. /// <summary>
  31. /// The key for a setting that indicates whether kestrel should bind to a unix socket.
  32. /// </summary>
  33. public const string BindToUnixSocketKey = "kestrel:socket";
  34. /// <summary>
  35. /// The key for the unix socket path.
  36. /// </summary>
  37. public const string UnixSocketPathKey = "kestrel:socketPath";
  38. /// <summary>
  39. /// Gets a value indicating whether the application should host static web content from the <see cref="IConfiguration"/>.
  40. /// </summary>
  41. /// <param name="configuration">The configuration to retrieve the value from.</param>
  42. /// <returns>The parsed config value.</returns>
  43. /// <exception cref="FormatException">The config value is not a valid bool string. See <see cref="bool.Parse(string)"/>.</exception>
  44. public static bool HostWebClient(this IConfiguration configuration)
  45. => configuration.GetValue<bool>(HostWebClientKey);
  46. /// <summary>
  47. /// Gets the FFmpeg probe size from the <see cref="IConfiguration" />.
  48. /// </summary>
  49. /// <param name="configuration">The configuration to read the setting from.</param>
  50. /// <returns>The FFmpeg probe size option.</returns>
  51. public static string GetFFmpegProbeSize(this IConfiguration configuration)
  52. => configuration[FfmpegProbeSizeKey];
  53. /// <summary>
  54. /// Gets the FFmpeg analyze duration from the <see cref="IConfiguration" />.
  55. /// </summary>
  56. /// <param name="configuration">The configuration to read the setting from.</param>
  57. /// <returns>The FFmpeg analyze duration option.</returns>
  58. public static string GetFFmpegAnalyzeDuration(this IConfiguration configuration)
  59. => configuration[FfmpegAnalyzeDurationKey];
  60. /// <summary>
  61. /// Gets a value indicating whether playlists should allow duplicate entries from the <see cref="IConfiguration"/>.
  62. /// </summary>
  63. /// <param name="configuration">The configuration to read the setting from.</param>
  64. /// <returns>True if playlists should allow duplicates, otherwise false.</returns>
  65. public static bool DoPlaylistsAllowDuplicates(this IConfiguration configuration)
  66. => configuration.GetValue<bool>(PlaylistsAllowDuplicatesKey);
  67. /// <summary>
  68. /// Gets a value indicating whether kestrel should bind to a unix socket from the <see cref="IConfiguration" />.
  69. /// </summary>
  70. /// <param name="configuration">The configuration to read the setting from.</param>
  71. /// <returns><c>true</c> if kestrel should bind to a unix socket, otherwise <c>false</c>.</returns>
  72. public static bool UseUnixSocket(this IConfiguration configuration)
  73. => configuration.GetValue<bool>(BindToUnixSocketKey);
  74. /// <summary>
  75. /// Gets the path for the unix socket from the <see cref="IConfiguration" />.
  76. /// </summary>
  77. /// <param name="configuration">The configuration to read the setting from.</param>
  78. /// <returns>The unix socket path.</returns>
  79. public static string GetUnixSocketPath(this IConfiguration configuration)
  80. => configuration[UnixSocketPathKey];
  81. }
  82. }