diff options
| author | WWWesten <4700006+WWWesten@users.noreply.github.com> | 2021-11-01 23:43:29 +0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-01 23:43:29 +0500 |
| commit | 0a14279e2a21bcb9654a06a2d49e1e4f0cc5329c (patch) | |
| tree | e1b1bd603b011ca98e5793e356326bf4a35a7050 /MediaBrowser.Common/Configuration/EncodingConfigurationExtensions.cs | |
| parent | f2817fef743eeb75a00782ceea363b2d3e7dc9f2 (diff) | |
| parent | 76eeb8f655424d295e73ced8349c6fefee6ddb12 (diff) | |
Merge branch 'jellyfin:master' into master
Diffstat (limited to 'MediaBrowser.Common/Configuration/EncodingConfigurationExtensions.cs')
| -rw-r--r-- | MediaBrowser.Common/Configuration/EncodingConfigurationExtensions.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Configuration/EncodingConfigurationExtensions.cs b/MediaBrowser.Common/Configuration/EncodingConfigurationExtensions.cs new file mode 100644 index 000000000..89740ae08 --- /dev/null +++ b/MediaBrowser.Common/Configuration/EncodingConfigurationExtensions.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using MediaBrowser.Model.Configuration; + +namespace MediaBrowser.Common.Configuration +{ + /// <summary> + /// Class containing extension methods for working with the encoding configuration. + /// </summary> + public static class EncodingConfigurationExtensions + { + /// <summary> + /// Gets the encoding options. + /// </summary> + /// <param name="configurationManager">The configuration manager.</param> + /// <returns>The encoding options.</returns> + public static EncodingOptions GetEncodingOptions(this IConfigurationManager configurationManager) + => configurationManager.GetConfiguration<EncodingOptions>("encoding"); + + /// <summary> + /// Retrieves the transcoding temp path from the encoding configuration, falling back to a default if no path + /// is specified in configuration. If the directory does not exist, it will be created. + /// </summary> + /// <param name="configurationManager">The configuration manager.</param> + /// <returns>The transcoding temp path.</returns> + /// <exception cref="UnauthorizedAccessException">If the directory does not exist, and the caller does not have the required permission to create it.</exception> + /// <exception cref="NotSupportedException">If there is a custom path transcoding path specified, but it is invalid.</exception> + /// <exception cref="IOException">If the directory does not exist, and it also could not be created.</exception> + public static string GetTranscodePath(this IConfigurationManager configurationManager) + { + // Get the configured path and fall back to a default + var transcodingTempPath = configurationManager.GetEncodingOptions().TranscodingTempPath; + if (string.IsNullOrEmpty(transcodingTempPath)) + { + transcodingTempPath = Path.Combine(configurationManager.CommonApplicationPaths.ProgramDataPath, "transcodes"); + } + + // Make sure the directory exists + Directory.CreateDirectory(transcodingTempPath); + return transcodingTempPath; + } + } +} |
