From 7f57ef068932b054eb390bba850f41af0a5437c4 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 11 Jan 2014 13:58:50 -0500 Subject: [PATCH] support configurable transcoding temporary path --- MediaBrowser.Api/ApiEntryPoint.cs | 2 +- .../Playback/BaseStreamingService.cs | 2 +- .../Playback/Hls/BaseHlsService.cs | 2 +- .../Playback/Hls/HlsSegmentResponseFilter.cs | 2 +- .../Playback/Hls/HlsSegmentService.cs | 8 ++--- .../IServerApplicationPaths.cs | 6 ++-- .../Configuration/ServerConfiguration.cs | 1 + .../ServerConfigurationManager.cs | 32 +++++++++++++++++++ .../ServerApplicationPaths.cs | 13 ++++---- 9 files changed, 51 insertions(+), 17 deletions(-) diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index d37e7f724c..6e79e80df4 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -71,7 +71,7 @@ namespace MediaBrowser.Api /// private void DeleteEncodedMediaCache() { - foreach (var file in Directory.EnumerateFiles(AppPaths.EncodedMediaCachePath) + foreach (var file in Directory.EnumerateFiles(AppPaths.TranscodingTempPath) .Where(i => EntityResolutionHelper.VideoFileExtensions.Contains(Path.GetExtension(i))) .ToList()) { diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index c400da5bf3..d9bd873cde 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -122,7 +122,7 @@ namespace MediaBrowser.Api.Playback /// System.String. protected virtual string GetOutputFilePath(StreamState state) { - var folder = ServerConfigurationManager.ApplicationPaths.EncodedMediaCachePath; + var folder = ServerConfigurationManager.ApplicationPaths.TranscodingTempPath; var outputFileExtension = GetOutputFileExtension(state); diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 9c42c77292..8ac8dc9fc2 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -31,7 +31,7 @@ namespace MediaBrowser.Api.Playback.Hls protected override string GetOutputFilePath(StreamState state) { - var folder = ServerConfigurationManager.ApplicationPaths.EncodedMediaCachePath; + var folder = ServerConfigurationManager.ApplicationPaths.TranscodingTempPath; var outputFileExtension = GetOutputFileExtension(state); diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs index ed4ca86717..10ea6bc639 100644 --- a/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs +++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs @@ -42,7 +42,7 @@ namespace MediaBrowser.Api.Playback.Hls Logger.Info("OnEndRequest " + playlistId); var normalizedPlaylistId = playlistId.Replace("-low", string.Empty); - foreach (var playlist in Directory.EnumerateFiles(ApplicationPaths.EncodedMediaCachePath, "*.m3u8") + foreach (var playlist in Directory.EnumerateFiles(ApplicationPaths.TranscodingTempPath, "*.m3u8") .Where(i => i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1) .ToList()) { diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs index 93e1a06a00..31583ac197 100644 --- a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs +++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs @@ -89,7 +89,7 @@ namespace MediaBrowser.Api.Playback.Hls var file = request.PlaylistId + Path.GetExtension(Request.PathInfo); - file = Path.Combine(_appPaths.EncodedMediaCachePath, file); + file = Path.Combine(_appPaths.TranscodingTempPath, file); return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite); } @@ -108,7 +108,7 @@ namespace MediaBrowser.Api.Playback.Hls { var file = request.SegmentId + Path.GetExtension(Request.PathInfo); - file = Path.Combine(_appPaths.EncodedMediaCachePath, file); + file = Path.Combine(_appPaths.TranscodingTempPath, file); OnBeginRequest(request.PlaylistId); @@ -124,7 +124,7 @@ namespace MediaBrowser.Api.Playback.Hls { var file = request.SegmentId + Path.GetExtension(Request.PathInfo); - file = Path.Combine(_appPaths.EncodedMediaCachePath, file); + file = Path.Combine(_appPaths.TranscodingTempPath, file); return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite); } @@ -137,7 +137,7 @@ namespace MediaBrowser.Api.Playback.Hls { var normalizedPlaylistId = playlistId.Replace("-low", string.Empty); - foreach (var playlist in Directory.EnumerateFiles(_appPaths.EncodedMediaCachePath, "*.m3u8") + foreach (var playlist in Directory.EnumerateFiles(_appPaths.TranscodingTempPath, "*.m3u8") .Where(i => i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1) .ToList()) { diff --git a/MediaBrowser.Controller/IServerApplicationPaths.cs b/MediaBrowser.Controller/IServerApplicationPaths.cs index f8b78299c4..e163ac31dd 100644 --- a/MediaBrowser.Controller/IServerApplicationPaths.cs +++ b/MediaBrowser.Controller/IServerApplicationPaths.cs @@ -95,10 +95,10 @@ namespace MediaBrowser.Controller string UserConfigurationDirectoryPath { get; } /// - /// Gets the FF MPEG stream cache path. + /// Gets the transcoding temporary path. /// - /// The FF MPEG stream cache path. - string EncodedMediaCachePath { get; } + /// The transcoding temporary path. + string TranscodingTempPath { get; } /// /// Gets the downloaded images data path. diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 02dd909f2b..b119bacdc5 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -220,6 +220,7 @@ namespace MediaBrowser.Model.Configuration public MetadataOptions BookOptions { get; set; } public bool EnableDebugEncodingLogging { get; set; } + public string TranscodingTempPath { get; set; } /// /// Initializes a new instance of the class. diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index 94438e3e0f..5ae3af5e22 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -60,6 +60,7 @@ namespace MediaBrowser.Server.Implementations.Configuration protected override void OnConfigurationUpdated() { UpdateItemsByNamePath(); + UpdateTranscodingTempPath(); base.OnConfigurationUpdated(); } @@ -74,6 +75,16 @@ namespace MediaBrowser.Server.Implementations.Configuration Configuration.ItemsByNamePath; } + /// + /// Updates the transcoding temporary path. + /// + private void UpdateTranscodingTempPath() + { + ((ServerApplicationPaths)ApplicationPaths).TranscodingTempPath = string.IsNullOrEmpty(Configuration.TranscodingTempPath) ? + null : + Configuration.TranscodingTempPath; + } + /// /// Replaces the configuration. /// @@ -84,6 +95,7 @@ namespace MediaBrowser.Server.Implementations.Configuration var newConfig = (ServerConfiguration) newConfiguration; ValidateItemByNamePath(newConfig); + ValidateTranscodingTempPath(newConfig); base.ReplaceConfiguration(newConfiguration); } @@ -107,5 +119,25 @@ namespace MediaBrowser.Server.Implementations.Configuration } } } + + /// + /// Validates the transcoding temporary path. + /// + /// The new configuration. + /// + private void ValidateTranscodingTempPath(ServerConfiguration newConfig) + { + var newPath = newConfig.TranscodingTempPath; + + if (!string.IsNullOrWhiteSpace(newPath) + && !string.Equals(Configuration.TranscodingTempPath ?? string.Empty, newPath)) + { + // Validate + if (!Directory.Exists(newPath)) + { + throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath)); + } + } + } } } diff --git a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs index db538f8dd0..abb60a1d58 100644 --- a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs +++ b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs @@ -200,15 +200,16 @@ namespace MediaBrowser.Server.Implementations } } - /// - /// Gets the FF MPEG stream cache path. - /// - /// The FF MPEG stream cache path. - public string EncodedMediaCachePath + private string _transcodingTempPath; + public string TranscodingTempPath { get { - return Path.Combine(CachePath, "encoded-media"); + return _transcodingTempPath ?? (_transcodingTempPath = Path.Combine(ProgramDataPath, "transcoding-temp")); + } + set + { + _transcodingTempPath = value; } }