ConfigurationExtensions.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 specifies the default redirect path
  12. /// to use for requests where the URL base prefix is invalid or missing..
  13. /// </summary>
  14. public const string DefaultRedirectKey = "DefaultRedirectPath";
  15. /// <summary>
  16. /// The key for the address override option.
  17. /// </summary>
  18. public const string AddressOverrideKey = "PublishedServerUrl";
  19. /// <summary>
  20. /// The key for a setting that indicates whether the application should host web client content.
  21. /// </summary>
  22. public const string HostWebClientKey = "hostwebclient";
  23. /// <summary>
  24. /// The key for the FFmpeg probe size option.
  25. /// </summary>
  26. public const string FfmpegProbeSizeKey = "FFmpeg:probesize";
  27. /// <summary>
  28. /// The key for the FFmpeg analyze duration option.
  29. /// </summary>
  30. public const string FfmpegAnalyzeDurationKey = "FFmpeg:analyzeduration";
  31. /// <summary>
  32. /// The key for the FFmpeg path option.
  33. /// </summary>
  34. public const string FfmpegPathKey = "ffmpeg";
  35. /// <summary>
  36. /// The key for a setting that indicates whether playlists should allow duplicate entries.
  37. /// </summary>
  38. public const string PlaylistsAllowDuplicatesKey = "playlists:allowDuplicates";
  39. /// <summary>
  40. /// The key for a setting that indicates whether kestrel should bind to a unix socket.
  41. /// </summary>
  42. public const string BindToUnixSocketKey = "kestrel:socket";
  43. /// <summary>
  44. /// The key for the unix socket path.
  45. /// </summary>
  46. public const string UnixSocketPathKey = "kestrel:socketPath";
  47. /// <summary>
  48. /// The permissions for the unix socket.
  49. /// </summary>
  50. public const string UnixSocketPermissionsKey = "kestrel:socketPermissions";
  51. /// <summary>
  52. /// Gets a value indicating whether the application should host static web content from the <see cref="IConfiguration"/>.
  53. /// </summary>
  54. /// <param name="configuration">The configuration to retrieve the value from.</param>
  55. /// <returns>The parsed config value.</returns>
  56. /// <exception cref="FormatException">The config value is not a valid bool string. See <see cref="bool.Parse(string)"/>.</exception>
  57. public static bool HostWebClient(this IConfiguration configuration)
  58. => configuration.GetValue<bool>(HostWebClientKey);
  59. /// <summary>
  60. /// Gets the FFmpeg probe size from the <see cref="IConfiguration" />.
  61. /// </summary>
  62. /// <param name="configuration">The configuration to read the setting from.</param>
  63. /// <returns>The FFmpeg probe size option.</returns>
  64. public static string? GetFFmpegProbeSize(this IConfiguration configuration)
  65. => configuration[FfmpegProbeSizeKey];
  66. /// <summary>
  67. /// Gets the FFmpeg analyze duration from the <see cref="IConfiguration" />.
  68. /// </summary>
  69. /// <param name="configuration">The configuration to read the setting from.</param>
  70. /// <returns>The FFmpeg analyze duration option.</returns>
  71. public static string? GetFFmpegAnalyzeDuration(this IConfiguration configuration)
  72. => configuration[FfmpegAnalyzeDurationKey];
  73. /// <summary>
  74. /// Gets a value indicating whether playlists should allow duplicate entries from the <see cref="IConfiguration"/>.
  75. /// </summary>
  76. /// <param name="configuration">The configuration to read the setting from.</param>
  77. /// <returns>True if playlists should allow duplicates, otherwise false.</returns>
  78. public static bool DoPlaylistsAllowDuplicates(this IConfiguration configuration)
  79. => configuration.GetValue<bool>(PlaylistsAllowDuplicatesKey);
  80. /// <summary>
  81. /// Gets a value indicating whether kestrel should bind to a unix socket from the <see cref="IConfiguration" />.
  82. /// </summary>
  83. /// <param name="configuration">The configuration to read the setting from.</param>
  84. /// <returns><c>true</c> if kestrel should bind to a unix socket, otherwise <c>false</c>.</returns>
  85. public static bool UseUnixSocket(this IConfiguration configuration)
  86. => configuration.GetValue<bool>(BindToUnixSocketKey);
  87. /// <summary>
  88. /// Gets the path for the unix socket from the <see cref="IConfiguration" />.
  89. /// </summary>
  90. /// <param name="configuration">The configuration to read the setting from.</param>
  91. /// <returns>The unix socket path.</returns>
  92. public static string? GetUnixSocketPath(this IConfiguration configuration)
  93. => configuration[UnixSocketPathKey];
  94. /// <summary>
  95. /// Gets the permissions for the unix socket from the <see cref="IConfiguration" />.
  96. /// </summary>
  97. /// <param name="configuration">The configuration to read the setting from.</param>
  98. /// <returns>The unix socket permissions.</returns>
  99. public static string? GetUnixSocketPermissions(this IConfiguration configuration)
  100. => configuration[UnixSocketPermissionsKey];
  101. }
  102. }