ConfigurationExtensions.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 skipping FFmpeg validation.
  29. /// </summary>
  30. public const string FfmpegSkipValidationKey = "FFmpeg:novalidation";
  31. /// <summary>
  32. /// The key for the FFmpeg analyze duration option.
  33. /// </summary>
  34. public const string FfmpegAnalyzeDurationKey = "FFmpeg:analyzeduration";
  35. /// <summary>
  36. /// The key for the FFmpeg image extraction performance tradeoff option.
  37. /// </summary>
  38. public const string FfmpegImgExtractPerfTradeoffKey = "FFmpeg:imgExtractPerfTradeoff";
  39. /// <summary>
  40. /// The key for the FFmpeg path option.
  41. /// </summary>
  42. public const string FfmpegPathKey = "ffmpeg";
  43. /// <summary>
  44. /// The key for a setting that indicates whether kestrel should bind to a unix socket.
  45. /// </summary>
  46. public const string BindToUnixSocketKey = "kestrel:socket";
  47. /// <summary>
  48. /// The key for the unix socket path.
  49. /// </summary>
  50. public const string UnixSocketPathKey = "kestrel:socketPath";
  51. /// <summary>
  52. /// The permissions for the unix socket.
  53. /// </summary>
  54. public const string UnixSocketPermissionsKey = "kestrel:socketPermissions";
  55. /// <summary>
  56. /// The cache size of the SQL database, see cache_size.
  57. /// </summary>
  58. public const string SqliteCacheSizeKey = "sqlite:cacheSize";
  59. /// <summary>
  60. /// The key for a setting that indicates whether the application should detect network status change.
  61. /// </summary>
  62. public const string DetectNetworkChangeKey = "DetectNetworkChange";
  63. /// <summary>
  64. /// Gets a value indicating whether the application should host static web content from the <see cref="IConfiguration"/>.
  65. /// </summary>
  66. /// <param name="configuration">The configuration to retrieve the value from.</param>
  67. /// <returns>The parsed config value.</returns>
  68. /// <exception cref="FormatException">The config value is not a valid bool string. See <see cref="bool.Parse(string)"/>.</exception>
  69. public static bool HostWebClient(this IConfiguration configuration)
  70. => configuration.GetValue<bool>(HostWebClientKey);
  71. /// <summary>
  72. /// Gets the FFmpeg probe size from the <see cref="IConfiguration" />.
  73. /// </summary>
  74. /// <param name="configuration">The configuration to read the setting from.</param>
  75. /// <returns>The FFmpeg probe size option.</returns>
  76. public static string? GetFFmpegProbeSize(this IConfiguration configuration)
  77. => configuration[FfmpegProbeSizeKey];
  78. /// <summary>
  79. /// Gets the FFmpeg analyze duration from the <see cref="IConfiguration" />.
  80. /// </summary>
  81. /// <param name="configuration">The configuration to read the setting from.</param>
  82. /// <returns>The FFmpeg analyze duration option.</returns>
  83. public static string? GetFFmpegAnalyzeDuration(this IConfiguration configuration)
  84. => configuration[FfmpegAnalyzeDurationKey];
  85. /// <summary>
  86. /// Gets a value indicating whether the server should validate FFmpeg during startup.
  87. /// </summary>
  88. /// <param name="configuration">The configuration to read the setting from.</param>
  89. /// <returns><c>true</c> if the server should validate FFmpeg during startup, otherwise <c>false</c>.</returns>
  90. public static bool GetFFmpegSkipValidation(this IConfiguration configuration)
  91. => configuration.GetValue<bool>(FfmpegSkipValidationKey);
  92. /// <summary>
  93. /// Gets a value indicating whether the server should trade off for performance during FFmpeg image extraction.
  94. /// </summary>
  95. /// <param name="configuration">The configuration to read the setting from.</param>
  96. /// <returns><c>true</c> if the server should trade off for performance during FFmpeg image extraction, otherwise <c>false</c>.</returns>
  97. public static bool GetFFmpegImgExtractPerfTradeoff(this IConfiguration configuration)
  98. => configuration.GetValue<bool>(FfmpegImgExtractPerfTradeoffKey);
  99. /// <summary>
  100. /// Gets a value indicating whether kestrel should bind to a unix socket from the <see cref="IConfiguration" />.
  101. /// </summary>
  102. /// <param name="configuration">The configuration to read the setting from.</param>
  103. /// <returns><c>true</c> if kestrel should bind to a unix socket, otherwise <c>false</c>.</returns>
  104. public static bool UseUnixSocket(this IConfiguration configuration)
  105. => configuration.GetValue<bool>(BindToUnixSocketKey);
  106. /// <summary>
  107. /// Gets the path for the unix socket from the <see cref="IConfiguration" />.
  108. /// </summary>
  109. /// <param name="configuration">The configuration to read the setting from.</param>
  110. /// <returns>The unix socket path.</returns>
  111. public static string? GetUnixSocketPath(this IConfiguration configuration)
  112. => configuration[UnixSocketPathKey];
  113. /// <summary>
  114. /// Gets the permissions for the unix socket from the <see cref="IConfiguration" />.
  115. /// </summary>
  116. /// <param name="configuration">The configuration to read the setting from.</param>
  117. /// <returns>The unix socket permissions.</returns>
  118. public static string? GetUnixSocketPermissions(this IConfiguration configuration)
  119. => configuration[UnixSocketPermissionsKey];
  120. /// <summary>
  121. /// Gets the cache_size from the <see cref="IConfiguration" />.
  122. /// </summary>
  123. /// <param name="configuration">The configuration to read the setting from.</param>
  124. /// <returns>The sqlite cache size.</returns>
  125. public static int? GetSqliteCacheSize(this IConfiguration configuration)
  126. => configuration.GetValue<int?>(SqliteCacheSizeKey);
  127. }
  128. }