using System;
using System.IO;
using MediaBrowser.Model.Configuration;
namespace MediaBrowser.Common.Configuration
{
///
/// Class containing extension methods for working with the encoding configuration.
///
public static class EncodingConfigurationExtensions
{
///
/// Gets the encoding options.
///
/// The configuration manager.
/// The encoding options.
public static EncodingOptions GetEncodingOptions(this IConfigurationManager configurationManager)
=> configurationManager.GetConfiguration("encoding");
///
/// 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.
///
/// The configuration manager.
/// The transcoding temp path.
/// If the directory does not exist, and the caller does not have the required permission to create it.
/// If there is a custom path transcoding path specified, but it is invalid.
/// If the directory does not exist, and it also could not be created.
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;
}
}
}