2020-04-26 19:04:57 +00:00
using System ;
2019-11-08 11:49:00 +00:00
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>
2020-04-26 19:04:57 +00:00
/// 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.
2019-11-08 11:49:00 +00:00
/// </summary>
2020-04-26 19:04:57 +00:00
/// <param name="configurationManager">The configuration manager.</param>
2019-11-08 11:49:00 +00:00
/// <returns>The transcoding temp path.</returns>
2020-04-26 19:04:57 +00:00
/// <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>
2019-11-08 11:49:00 +00:00
public static string GetTranscodePath ( this IConfigurationManager configurationManager )
2019-12-04 21:18:37 +00:00
{
2020-04-26 19:04:57 +00:00
// Get the configured path and fall back to a default
2019-12-04 21:18:37 +00:00
var transcodingTempPath = configurationManager . GetEncodingOptions ( ) . TranscodingTempPath ;
if ( string . IsNullOrEmpty ( transcodingTempPath ) )
{
2022-07-11 16:56:58 +00:00
transcodingTempPath = Path . Combine ( configurationManager . CommonApplicationPaths . CachePath , "transcodes" ) ;
2019-12-04 21:18:37 +00:00
}
2020-04-26 19:04:57 +00:00
// Make sure the directory exists
Directory . CreateDirectory ( transcodingTempPath ) ;
2019-12-04 21:18:37 +00:00
return transcodingTempPath ;
}
2019-11-08 11:49:00 +00:00
}
}