EncodingConfigurationExtensions.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.IO;
  3. using MediaBrowser.Model.Configuration;
  4. namespace MediaBrowser.Common.Configuration
  5. {
  6. /// <summary>
  7. /// Class containing extension methods for working with the encoding configuration.
  8. /// </summary>
  9. public static class EncodingConfigurationExtensions
  10. {
  11. /// <summary>
  12. /// Gets the encoding options.
  13. /// </summary>
  14. /// <param name="configurationManager">The configuration manager.</param>
  15. /// <returns>The encoding options.</returns>
  16. public static EncodingOptions GetEncodingOptions(this IConfigurationManager configurationManager)
  17. => configurationManager.GetConfiguration<EncodingOptions>("encoding");
  18. /// <summary>
  19. /// Retrieves the transcoding temp path from the encoding configuration, falling back to a default if no path
  20. /// is specified in configuration. If the directory does not exist, it will be created.
  21. /// </summary>
  22. /// <param name="configurationManager">The configuration manager.</param>
  23. /// <returns>The transcoding temp path.</returns>
  24. /// <exception cref="UnauthorizedAccessException">If the directory does not exist, and the caller does not have the required permission to create it.</exception>
  25. /// <exception cref="NotSupportedException">If there is a custom path transcoding path specified, but it is invalid.</exception>
  26. /// <exception cref="IOException">If the directory does not exist, and it also could not be created.</exception>
  27. public static string GetTranscodePath(this IConfigurationManager configurationManager)
  28. {
  29. // Get the configured path and fall back to a default
  30. var transcodingTempPath = configurationManager.GetEncodingOptions().TranscodingTempPath;
  31. if (string.IsNullOrEmpty(transcodingTempPath))
  32. {
  33. transcodingTempPath = Path.Combine(configurationManager.CommonApplicationPaths.CachePath, "transcodes");
  34. }
  35. configurationManager.CommonApplicationPaths.CreateAndCheckMarker(transcodingTempPath, "transcode", true);
  36. return transcodingTempPath;
  37. }
  38. }
  39. }