ConfigurationExtensions.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /// Gets a value indicating whether the application should host static web content from the <see cref="IConfiguration"/>.
  32. /// </summary>
  33. /// <param name="configuration">The configuration to retrieve the value from.</param>
  34. /// <returns>The parsed config value.</returns>
  35. /// <exception cref="FormatException">The config value is not a valid bool string. See <see cref="bool.Parse(string)"/>.</exception>
  36. public static bool HostWebClient(this IConfiguration configuration)
  37. => configuration.GetValue<bool>(HostWebClientKey);
  38. /// <summary>
  39. /// Gets the FFmpeg probe size from the <see cref="IConfiguration" />.
  40. /// </summary>
  41. /// <param name="configuration">The configuration to read the setting from.</param>
  42. /// <returns>The FFmpeg probe size option.</returns>
  43. public static string GetFFmpegProbeSize(this IConfiguration configuration)
  44. => configuration[FfmpegProbeSizeKey];
  45. /// <summary>
  46. /// Gets the FFmpeg analyze duration from the <see cref="IConfiguration" />.
  47. /// </summary>
  48. /// <param name="configuration">The configuration to read the setting from.</param>
  49. /// <returns>The FFmpeg analyze duration option.</returns>
  50. public static string GetFFmpegAnalyzeDuration(this IConfiguration configuration)
  51. => configuration[FfmpegAnalyzeDurationKey];
  52. /// <summary>
  53. /// Gets a value indicating whether playlists should allow duplicate entries from the <see cref="IConfiguration"/>.
  54. /// </summary>
  55. /// <param name="configuration">The configuration to read the setting from.</param>
  56. /// <returns>True if playlists should allow duplicates, otherwise false.</returns>
  57. public static bool DoPlaylistsAllowDuplicates(this IConfiguration configuration)
  58. => configuration.GetValue<bool>(PlaylistsAllowDuplicatesKey);
  59. }
  60. }