From 2e408e40c015b34b365d0e0ef4d7a20fc02b0b80 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 4 Jun 2013 12:48:23 -0400 Subject: [PATCH 1/2] defer path creation when possible --- .../Playback/BaseStreamingService.cs | 7 + .../BaseApplicationPaths.cs | 10 +- MediaBrowser.Controller/Entities/User.cs | 15 +- .../BaseApplicationConfiguration.cs | 2 +- .../Library/LibraryManager.cs | 6 + .../ServerApplicationPaths.cs | 228 ++---------------- Nuget/MediaBrowser.Common.Internal.nuspec | 3 +- 7 files changed, 38 insertions(+), 233 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 9d5f73141c..602acff09c 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -562,6 +562,13 @@ namespace MediaBrowser.Api.Playback /// Task. protected async Task StartFfMpeg(StreamState state, string outputPath) { + var parentPath = Path.GetDirectoryName(outputPath); + + if (!Directory.Exists(parentPath)) + { + Directory.CreateDirectory(parentPath); + } + var video = state.Item as Video; if (video != null && video.VideoType == VideoType.Iso && video.IsoType.HasValue && IsoManager.CanMount(video.Path)) diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs index 82a35fc511..f6667f2364 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs @@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Implementations /// /// Gets the path to the system folder /// - public string ProgramSystemPath { get { return Path.Combine(ProgramDataPath, "System"); } } + public string ProgramSystemPath { get { return Path.Combine(ProgramDataPath, "system"); } } /// /// The _data directory @@ -160,7 +160,7 @@ namespace MediaBrowser.Common.Implementations { if (_tempUpdatePath == null) { - _tempUpdatePath = Path.Combine(ProgramDataPath, "Updates"); + _tempUpdatePath = Path.Combine(ProgramDataPath, "updates"); if (!Directory.Exists(_tempUpdatePath)) { Directory.CreateDirectory(_tempUpdatePath); @@ -219,10 +219,6 @@ namespace MediaBrowser.Common.Implementations } } - /// - /// The _system configuration file path - /// - private string _systemConfigurationFilePath; /// /// Gets the path to the system configuration file /// @@ -231,7 +227,7 @@ namespace MediaBrowser.Common.Implementations { get { - return _systemConfigurationFilePath ?? (_systemConfigurationFilePath = Path.Combine(ConfigurationDirectoryPath, "system.xml")); + return Path.Combine(ConfigurationDirectoryPath, "system.xml"); } } diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs index 65884332aa..e991820e3e 100644 --- a/MediaBrowser.Controller/Entities/User.cs +++ b/MediaBrowser.Controller/Entities/User.cs @@ -28,19 +28,14 @@ namespace MediaBrowser.Controller.Entities { get { - if (Configuration.UseCustomLibrary) - { - var rootFolderPath = GetRootFolderPath(Name); + var path = Configuration.UseCustomLibrary ? GetRootFolderPath(Name) : ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; - if (!Directory.Exists(rootFolderPath)) - { - Directory.CreateDirectory(rootFolderPath); - } - - return rootFolderPath; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); } - return ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; + return path; } } diff --git a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs index 86f774a017..b99fefcca3 100644 --- a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs +++ b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs @@ -50,7 +50,7 @@ namespace MediaBrowser.Model.Configuration public BaseApplicationConfiguration() { EnableAutoUpdate = true; - LogFileRetentionDays = 7; + LogFileRetentionDays = 3; #if (DEBUG) EnableDebugLevelLogging = true; diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index f9c8e9a31c..8a19a8d3fb 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -558,6 +558,12 @@ namespace MediaBrowser.Server.Implementations.Library public AggregateFolder CreateRootFolder() { var rootFolderPath = ConfigurationManager.ApplicationPaths.RootFolderPath; + + if (!Directory.Exists(rootFolderPath)) + { + Directory.CreateDirectory(rootFolderPath); + } + var rootFolder = RetrieveItem(rootFolderPath.GetMBId(typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(rootFolderPath); // Add in the plug-in folders diff --git a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs index c30c1b9db2..655876c8c5 100644 --- a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs +++ b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs @@ -26,10 +26,6 @@ namespace MediaBrowser.Server.Implementations { } #endif - /// - /// The _root folder path - /// - private string _rootFolderPath; /// /// Gets the path to the base root media directory /// @@ -38,22 +34,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_rootFolderPath == null) - { - _rootFolderPath = Path.Combine(ProgramDataPath, "Root"); - if (!Directory.Exists(_rootFolderPath)) - { - Directory.CreateDirectory(_rootFolderPath); - } - } - return _rootFolderPath; + return Path.Combine(ProgramDataPath, "root"); } } - /// - /// The _default user views path - /// - private string _defaultUserViewsPath; /// /// Gets the path to the default user view directory. Used if no specific user view is defined. /// @@ -62,22 +46,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_defaultUserViewsPath == null) - { - _defaultUserViewsPath = Path.Combine(RootFolderPath, "Default"); - if (!Directory.Exists(_defaultUserViewsPath)) - { - Directory.CreateDirectory(_defaultUserViewsPath); - } - } - return _defaultUserViewsPath; + return Path.Combine(RootFolderPath, "default"); } } - /// - /// The _localization path - /// - private string _localizationPath; /// /// Gets the path to localization data. /// @@ -86,15 +58,7 @@ namespace MediaBrowser.Server.Implementations { get { - if (_localizationPath == null) - { - _localizationPath = Path.Combine(ProgramDataPath, "Localization"); - if (!Directory.Exists(_localizationPath)) - { - Directory.CreateDirectory(_localizationPath); - } - } - return _localizationPath; + return Path.Combine(ProgramDataPath, "localization"); } } @@ -110,36 +74,14 @@ namespace MediaBrowser.Server.Implementations { get { - if (_ibnPath == null) - { - _ibnPath = Path.Combine(ProgramDataPath, "ImagesByName"); - if (!Directory.Exists(_ibnPath)) - { - Directory.CreateDirectory(_ibnPath); - } - } - - return _ibnPath; + return _ibnPath ?? (_ibnPath = Path.Combine(ProgramDataPath, "ImagesByName")); } set { _ibnPath = value; - - _peoplePath = null; - _studioPath = null; - _genrePath = null; - _yearPath = null; - _musicArtistsPath = null; - _generalPath = null; - _ratingsPath = null; - _mediaInfoImagesPath = null; } } - /// - /// The _people path - /// - private string _peoplePath; /// /// Gets the path to the People directory /// @@ -148,23 +90,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_peoplePath == null) - { - _peoplePath = Path.Combine(ItemsByNamePath, "People"); - if (!Directory.Exists(_peoplePath)) - { - Directory.CreateDirectory(_peoplePath); - } - } - - return _peoplePath; + return Path.Combine(ItemsByNamePath, "People"); } } - /// - /// The _genre path - /// - private string _genrePath; /// /// Gets the path to the Genre directory /// @@ -173,23 +102,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_genrePath == null) - { - _genrePath = Path.Combine(ItemsByNamePath, "Genre"); - if (!Directory.Exists(_genrePath)) - { - Directory.CreateDirectory(_genrePath); - } - } - - return _genrePath; + return Path.Combine(ItemsByNamePath, "Genre"); } } - /// - /// The _studio path - /// - private string _studioPath; /// /// Gets the path to the Studio directory /// @@ -198,23 +114,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_studioPath == null) - { - _studioPath = Path.Combine(ItemsByNamePath, "Studio"); - if (!Directory.Exists(_studioPath)) - { - Directory.CreateDirectory(_studioPath); - } - } - - return _studioPath; + return Path.Combine(ItemsByNamePath, "Studio"); } } - /// - /// The _year path - /// - private string _yearPath; /// /// Gets the path to the Year directory /// @@ -223,23 +126,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_yearPath == null) - { - _yearPath = Path.Combine(ItemsByNamePath, "Year"); - if (!Directory.Exists(_yearPath)) - { - Directory.CreateDirectory(_yearPath); - } - } - - return _yearPath; + return Path.Combine(ItemsByNamePath, "Year"); } } - /// - /// The _general path - /// - private string _generalPath; /// /// Gets the path to the General IBN directory /// @@ -248,23 +138,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_generalPath == null) - { - _generalPath = Path.Combine(ItemsByNamePath, "General"); - if (!Directory.Exists(_generalPath)) - { - Directory.CreateDirectory(_generalPath); - } - } - - return _generalPath; + return Path.Combine(ItemsByNamePath, "general"); } } - /// - /// The _ratings path - /// - private string _ratingsPath; /// /// Gets the path to the Ratings IBN directory /// @@ -273,23 +150,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_ratingsPath == null) - { - _ratingsPath = Path.Combine(ItemsByNamePath, "Ratings"); - if (!Directory.Exists(_ratingsPath)) - { - Directory.CreateDirectory(_ratingsPath); - } - } - - return _ratingsPath; + return Path.Combine(ItemsByNamePath, "ratings"); } } - /// - /// The _media info images path - /// - private string _mediaInfoImagesPath; /// /// Gets the media info images path. /// @@ -298,23 +162,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_mediaInfoImagesPath == null) - { - _mediaInfoImagesPath = Path.Combine(ItemsByNamePath, "MediaInfo"); - if (!Directory.Exists(_mediaInfoImagesPath)) - { - Directory.CreateDirectory(_mediaInfoImagesPath); - } - } - - return _mediaInfoImagesPath; + return Path.Combine(ItemsByNamePath, "mediainfo"); } } - /// - /// The _user configuration directory path - /// - private string _userConfigurationDirectoryPath; /// /// Gets the path to the user configuration directory /// @@ -323,22 +174,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_userConfigurationDirectoryPath == null) - { - _userConfigurationDirectoryPath = Path.Combine(ConfigurationDirectoryPath, "users"); - if (!Directory.Exists(_userConfigurationDirectoryPath)) - { - Directory.CreateDirectory(_userConfigurationDirectoryPath); - } - } - return _userConfigurationDirectoryPath; + return Path.Combine(ConfigurationDirectoryPath, "users"); } } - /// - /// The _f F MPEG stream cache path - /// - private string _fFMpegStreamCachePath; /// /// Gets the FF MPEG stream cache path. /// @@ -347,24 +186,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_fFMpegStreamCachePath == null) - { - _fFMpegStreamCachePath = Path.Combine(CachePath, "encoded-media"); - - if (!Directory.Exists(_fFMpegStreamCachePath)) - { - Directory.CreateDirectory(_fFMpegStreamCachePath); - } - } - - return _fFMpegStreamCachePath; + return Path.Combine(CachePath, "encoded-media"); } } - /// - /// The _images data path - /// - private string _downloadedImagesDataPath; /// /// Gets the images data path. /// @@ -373,24 +198,10 @@ namespace MediaBrowser.Server.Implementations { get { - if (_downloadedImagesDataPath == null) - { - _downloadedImagesDataPath = Path.Combine(DataPath, "remote-images"); - - if (!Directory.Exists(_downloadedImagesDataPath)) - { - Directory.CreateDirectory(_downloadedImagesDataPath); - } - } - - return _downloadedImagesDataPath; + return Path.Combine(DataPath, "remote-images"); } } - /// - /// The _music artists path - /// - private string _musicArtistsPath; /// /// Gets the artists path. /// @@ -399,16 +210,7 @@ namespace MediaBrowser.Server.Implementations { get { - if (_musicArtistsPath == null) - { - _musicArtistsPath = Path.Combine(ItemsByNamePath, "Artists"); - if (!Directory.Exists(_musicArtistsPath)) - { - Directory.CreateDirectory(_musicArtistsPath); - } - } - - return _musicArtistsPath; + return Path.Combine(ItemsByNamePath, "artists"); } } } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 5425e0b9a7..54f513892d 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -9,7 +9,7 @@ https://github.com/MediaBrowser/MediaBrowser http://www.mb3admin.com/images/mb3icons1-1.png false - Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption. + Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 @@ -20,6 +20,5 @@ - \ No newline at end of file From 5f32d9794d5cbc14d306e59a9287d86c940b956b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 4 Jun 2013 12:53:36 -0400 Subject: [PATCH 2/2] added back image enhancer method --- .../Drawing/ImageManager.cs | 35 +++++++++++++++++++ Nuget/MediaBrowser.Common.Internal.nuspec | 4 +-- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Controller/Drawing/ImageManager.cs b/MediaBrowser.Controller/Drawing/ImageManager.cs index b8406438c9..14994ac5ce 100644 --- a/MediaBrowser.Controller/Drawing/ImageManager.cs +++ b/MediaBrowser.Controller/Drawing/ImageManager.cs @@ -576,6 +576,41 @@ namespace MediaBrowser.Controller.Drawing return croppedImagePath; } + /// + /// Gets the enhanced image. + /// + /// The original image path. + /// The date modified. + /// The item. + /// Type of the image. + /// Index of the image. + /// Task{System.String}. + /// item + public Task GetEnhancedImage(string originalImagePath, DateTime dateModified, BaseItem item, ImageType imageType, int imageIndex) + { + if (item == null) + { + throw new ArgumentNullException("item"); + } + + var supportedImageEnhancers = ImageEnhancers.Where(i => + { + try + { + return i.Supports(item, imageType); + } + catch (Exception ex) + { + _logger.ErrorException("Error in image enhancer: {0}", ex, i.GetType().Name); + + return false; + } + + }).ToList(); + + return GetEnhancedImage(originalImagePath, dateModified, item, imageType, imageIndex, supportedImageEnhancers); + } + /// /// Runs an image through the image enhancers, caches the result, and returns the cached path /// diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 54f513892d..cd5b3c54bc 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.113 + 3.0.114 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 1b03690efe..b4520fc2c5 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.113 + 3.0.114 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 48ebcad5f3..e1fabbea77 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.113 + 3.0.114 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +