diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations')
6 files changed, 75 insertions, 52 deletions
diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index ce39ffc06..fbb5a2010 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -94,29 +94,20 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder } /// <summary> - /// The _media tools path + /// Gets the media tools path. /// </summary> - private string _mediaToolsPath; - /// <summary> - /// Gets the folder path to tools - /// </summary> - /// <value>The media tools path.</value> - private string MediaToolsPath + /// <param name="create">if set to <c>true</c> [create].</param> + /// <returns>System.String.</returns> + private string GetMediaToolsPath(bool create) { - get - { - if (_mediaToolsPath == null) - { - _mediaToolsPath = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg"); - - if (!Directory.Exists(_mediaToolsPath)) - { - Directory.CreateDirectory(_mediaToolsPath); - } - } + var path = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg"); - return _mediaToolsPath; + if (create && !Directory.Exists(path)) + { + Directory.CreateDirectory(path); } + + return path; } /// <summary> @@ -185,7 +176,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder var filename = resource.Substring(resource.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) + prefix.Length); - var versionedDirectoryPath = Path.Combine(MediaToolsPath, Path.GetFileNameWithoutExtension(filename)); + var versionedDirectoryPath = Path.Combine(GetMediaToolsPath(true), Path.GetFileNameWithoutExtension(filename)); if (!Directory.Exists(versionedDirectoryPath)) { @@ -570,14 +561,14 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder } var offsetParam = offset.Ticks > 0 ? "-ss " + offset.TotalSeconds + " " : string.Empty; - + var process = new Process { StartInfo = new ProcessStartInfo { RedirectStandardOutput = false, RedirectStandardError = true, - + CreateNoWindow = true, UseShellExecute = false, FileName = FFMpegPath, @@ -744,7 +735,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder RedirectStandardOutput = false, RedirectStandardError = true, - + FileName = FFMpegPath, Arguments = string.Format("{0}-i {1} -map 0:{2} -an -vn -c:s ass \"{3}\"", offsetParam, inputPath, subtitleStreamIndex, outputPath), WindowStyle = ProcessWindowStyle.Hidden, @@ -759,7 +750,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder var logFilePath = Path.Combine(_appPaths.LogDirectoryPath, "ffmpeg-sub-extract-" + Guid.NewGuid() + ".txt"); var logFileStream = new FileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); - + try { process.Start(); diff --git a/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs b/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs index 2ba222ca5..ea1b83dec 100644 --- a/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs +++ b/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs @@ -328,9 +328,7 @@ namespace MediaBrowser.Server.Implementations.Providers public async Task<string> SaveImage(BaseItem item, Stream source, string targetName, bool saveLocally, CancellationToken cancellationToken) { //download and save locally - var localPath = (saveLocally && item.MetaLocation != null) ? - Path.Combine(item.MetaLocation, targetName) : - _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Path.ToLower(), targetName); + var localPath = GetSavePath(item, targetName, saveLocally); if (saveLocally) // queue to media directories { @@ -374,9 +372,18 @@ namespace MediaBrowser.Server.Implementations.Providers /// <returns>System.String.</returns> public string GetSavePath(BaseItem item, string targetFileName, bool saveLocally) { - return (saveLocally && item.MetaLocation != null) ? + var path = (saveLocally && item.MetaLocation != null) ? Path.Combine(item.MetaLocation, targetFileName) : _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Id.ToString(), targetFileName); + + var parentPath = Path.GetDirectoryName(path); + + if (!Directory.Exists(parentPath)) + { + Directory.CreateDirectory(parentPath); + } + + return path; } /// <summary> diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs index 95dc4e7ae..2d9d5abfe 100644 --- a/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs +++ b/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs @@ -168,6 +168,14 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks if (!success) { previouslyFailedImages.Add(key); + + var parentPath = Path.GetDirectoryName(failHistoryPath); + + if (!Directory.Exists(parentPath)) + { + Directory.CreateDirectory(parentPath); + } + _jsonSerializer.SerializeToFile(previouslyFailedImages, failHistoryPath); } diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/ImageCleanupTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/ImageCleanupTask.cs index 0c3016552..0e78824c1 100644 --- a/MediaBrowser.Server.Implementations/ScheduledTasks/ImageCleanupTask.cs +++ b/MediaBrowser.Server.Implementations/ScheduledTasks/ImageCleanupTask.cs @@ -165,7 +165,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks var specialFeattures = _itemRepo.GetItems(movie.SpecialFeatureIds).ToList(); images = specialFeattures.Aggregate(images, (current, subItem) => current.Concat(GetPathsInUse(subItem))); } - + return images; } @@ -176,13 +176,20 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks /// <returns>IEnumerable{System.String}.</returns> private IEnumerable<string> GetFiles(string path) { - return Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) - .Where(i => - { - var ext = Path.GetExtension(i); + try + { + return Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) + .Where(i => + { + var ext = Path.GetExtension(i); - return !string.IsNullOrEmpty(ext) && BaseItem.SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase); - }); + return !string.IsNullOrEmpty(ext) && BaseItem.SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase); + }); + } + catch (DirectoryNotFoundException) + { + return new string[] { }; + } } /// <summary> diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/VideoImagesTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/VideoImagesTask.cs index f0afe6358..2233f6fdf 100644 --- a/MediaBrowser.Server.Implementations/ScheduledTasks/VideoImagesTask.cs +++ b/MediaBrowser.Server.Implementations/ScheduledTasks/VideoImagesTask.cs @@ -8,14 +8,15 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Providers.MediaInfo; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Logging; +using MoreLinq; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Model.Logging; -using MoreLinq; namespace MediaBrowser.Server.Implementations.ScheduledTasks { @@ -263,7 +264,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks var path = ImageCache.GetResourcePath(filename, ".jpg"); - if (!ImageCache.ContainsFilePath(path)) + if (!File.Exists(path)) { var semaphore = GetLock(path); @@ -271,10 +272,17 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); // Check again - if (!ImageCache.ContainsFilePath(path)) + if (!File.Exists(path)) { try { + var parentPath = Path.GetDirectoryName(path); + + if (!Directory.Exists(parentPath)) + { + Directory.CreateDirectory(parentPath); + } + await ExtractImageInternal(item, path, cancellationToken).ConfigureAwait(false); } finally diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs index a0acd523e..bead1360b 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs @@ -471,20 +471,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite /// <summary> /// Gets the critic reviews path. /// </summary> - /// <value>The critic reviews path.</value> - private string CriticReviewsPath + /// <param name="create">if set to <c>true</c> [create].</param> + /// <returns>System.String.</returns> + private string GetCriticReviewsPath(bool create) { - get - { - var path = Path.Combine(_appPaths.DataPath, "critic-reviews"); - - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } + var path = Path.Combine(_appPaths.DataPath, "critic-reviews"); - return path; + if (create && !Directory.Exists(path)) + { + Directory.CreateDirectory(path); } + + return path; } /// <summary> @@ -499,10 +497,14 @@ namespace MediaBrowser.Server.Implementations.Sqlite try { - var path = Path.Combine(CriticReviewsPath, itemId + ".json"); + var path = Path.Combine(GetCriticReviewsPath(false), itemId + ".json"); return _jsonSerializer.DeserializeFromFile<List<ItemReview>>(path); } + catch (DirectoryNotFoundException) + { + return new List<ItemReview>(); + } catch (FileNotFoundException) { return new List<ItemReview>(); @@ -521,7 +523,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite { return Task.Run(() => { - var path = Path.Combine(CriticReviewsPath, itemId + ".json"); + var path = Path.Combine(GetCriticReviewsPath(true), itemId + ".json"); _jsonSerializer.SerializeToFile(criticReviews.ToList(), path); }); |
