From 04b6f23473c4091ce7caf9fbe79d424ac002c0e0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 29 Mar 2017 02:26:48 -0400 Subject: [PATCH 1/2] 3.2.9.1 --- BDInfo/BDROM.cs | 6 +- .../IO/ManagedFileSystem.cs | 41 ++++++++++--- Emby.Dlna/DlnaManager.cs | 30 +++------- .../FileOrganization/TvFolderOrganizer.cs | 3 +- .../Library/LibraryManager.cs | 58 +++++++++++-------- .../Library/Resolvers/BaseVideoResolver.cs | 2 +- .../Library/Resolvers/PhotoResolver.cs | 15 +++-- MediaBrowser.Api/Images/ImageByNameService.cs | 3 +- .../Playback/Hls/DynamicHlsService.cs | 18 +++--- MediaBrowser.Api/StartupWizardService.cs | 1 - MediaBrowser.Api/System/SystemService.cs | 3 +- .../Entities/AggregateFolder.cs | 1 + MediaBrowser.Controller/Entities/BaseItem.cs | 7 +-- .../Providers/DirectoryService.cs | 10 ++++ .../Providers/IDirectoryService.cs | 5 +- .../Images/CollectionFolderImageProvider.cs | 2 +- .../Images/EpisodeLocalImageProvider.cs | 3 +- .../Images/ImagesByNameImageProvider.cs | 2 +- .../InternalMetadataFolderImageProvider.cs | 2 +- .../Images/LocalImageProvider.cs | 53 +++++++++-------- .../Configuration/ServerConfiguration.cs | 1 - MediaBrowser.Model/IO/IFileSystem.cs | 5 +- .../MediaInfo/FFProbeProvider.cs | 1 - .../MediaInfo/FFProbeVideoInfo.cs | 3 +- .../MediaInfo/SubtitleResolver.cs | 17 +++--- .../TV/TheTVDB/TvdbSeriesProvider.cs | 2 +- 26 files changed, 157 insertions(+), 137 deletions(-) diff --git a/BDInfo/BDROM.cs b/BDInfo/BDROM.cs index 2faeb405e2..d42e381daa 100644 --- a/BDInfo/BDROM.cs +++ b/BDInfo/BDROM.cs @@ -135,13 +135,13 @@ namespace BDInfo { IsBDPlus = true; } - + if (DirectoryBDJO != null && _fileSystem.GetFiles(DirectoryBDJO.FullName).Any()) { IsBDJava = true; } - + if (DirectorySNP != null && GetFiles(DirectorySNP.FullName, ".mnv").Any()) { @@ -206,7 +206,7 @@ namespace BDInfo private IEnumerable GetFiles(string path, string extension) { - return _fileSystem.GetFiles(path).Where(i => string.Equals(i.Extension, extension, StringComparison.OrdinalIgnoreCase)); + return _fileSystem.GetFiles(path, new[] { extension }, false, false); } public void Scan() diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs index 0c1c02cd59..ed940eca5f 100644 --- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs +++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs @@ -657,14 +657,41 @@ namespace Emby.Common.Implementations.IO { var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return ToMetadata(path, new DirectoryInfo(path).EnumerateDirectories("*", searchOption)); + return ToMetadata(new DirectoryInfo(path).EnumerateDirectories("*", searchOption)); } public IEnumerable GetFiles(string path, bool recursive = false) + { + return GetFiles(path, null, true, recursive); + } + + public IEnumerable GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false) { var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return ToMetadata(path, new DirectoryInfo(path).EnumerateFiles("*", searchOption)); + // On linux and osx the search pattern is case sensitive + // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method + if (enableCaseSensitiveExtensions && extensions != null && extensions.Length == 1) + { + return ToMetadata(new DirectoryInfo(path).EnumerateFiles("*" + extensions[0], searchOption)); + } + + var files = new DirectoryInfo(path).EnumerateFiles("*", searchOption); + + if (extensions != null && extensions.Length > 0) + { + files = files.Where(i => + { + var ext = i.Extension; + if (ext == null) + { + return false; + } + return extensions.Contains(ext, StringComparer.OrdinalIgnoreCase); + }); + } + + return ToMetadata(files); } public IEnumerable GetFileSystemEntries(string path, bool recursive = false) @@ -674,14 +701,14 @@ namespace Emby.Common.Implementations.IO if (EnableFileSystemRequestConcat) { - return ToMetadata(path, directoryInfo.EnumerateDirectories("*", searchOption)) - .Concat(ToMetadata(path, directoryInfo.EnumerateFiles("*", searchOption))); + return ToMetadata(directoryInfo.EnumerateDirectories("*", searchOption)) + .Concat(ToMetadata(directoryInfo.EnumerateFiles("*", searchOption))); } - return ToMetadata(path, directoryInfo.EnumerateFileSystemInfos("*", searchOption)); + return ToMetadata(directoryInfo.EnumerateFileSystemInfos("*", searchOption)); } - private IEnumerable ToMetadata(string parentPath, IEnumerable infos) + private IEnumerable ToMetadata(IEnumerable infos) { return infos.Select(GetFileSystemMetadata); } @@ -776,7 +803,7 @@ namespace Emby.Common.Implementations.IO public virtual void SetExecutable(string path) { - + } } } diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs index 020038422a..8f62e6d27a 100644 --- a/Emby.Dlna/DlnaManager.cs +++ b/Emby.Dlna/DlnaManager.cs @@ -286,19 +286,12 @@ namespace Emby.Dlna { try { - var allFiles = _fileSystem.GetFiles(path) + var xmlFies = _fileSystem.GetFilePaths(path) + .Where(i => string.Equals(Path.GetExtension(i), ".xml", StringComparison.OrdinalIgnoreCase)) .ToList(); - var xmlFies = allFiles - .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) - .ToList(); - - var parseFiles = new List(); - - parseFiles.AddRange(xmlFies); - - return parseFiles - .Select(i => ParseProfileFile(i.FullName, type)) + return xmlFies + .Select(i => ParseProfileFile(i, type)) .Where(i => i != null) .ToList(); } @@ -322,16 +315,9 @@ namespace Emby.Dlna { DeviceProfile profile; - if (string.Equals(Path.GetExtension(path), ".xml", StringComparison.OrdinalIgnoreCase)) - { - var tempProfile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); + var tempProfile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); - profile = ReserializeProfile(tempProfile); - } - else - { - profile = (DeviceProfile)_jsonSerializer.DeserializeFromFile(typeof(DeviceProfile), path); - } + profile = ReserializeProfile(tempProfile); profile.Id = path.ToLower().GetMD5().ToString("N"); profile.ProfileType = type; @@ -553,15 +539,13 @@ namespace Emby.Dlna class DlnaProfileEntryPoint : IServerEntryPoint { private readonly IApplicationPaths _appPaths; - private readonly IJsonSerializer _jsonSerializer; private readonly IFileSystem _fileSystem; private readonly IXmlSerializer _xmlSerializer; - public DlnaProfileEntryPoint(IApplicationPaths appPaths, IFileSystem fileSystem, IJsonSerializer jsonSerializer, IXmlSerializer xmlSerializer) + public DlnaProfileEntryPoint(IApplicationPaths appPaths, IFileSystem fileSystem, IXmlSerializer xmlSerializer) { _appPaths = appPaths; _fileSystem = fileSystem; - _jsonSerializer = jsonSerializer; _xmlSerializer = xmlSerializer; } diff --git a/Emby.Server.Implementations/FileOrganization/TvFolderOrganizer.cs b/Emby.Server.Implementations/FileOrganization/TvFolderOrganizer.cs index 2850c3a610..b035fdcfd5 100644 --- a/Emby.Server.Implementations/FileOrganization/TvFolderOrganizer.cs +++ b/Emby.Server.Implementations/FileOrganization/TvFolderOrganizer.cs @@ -151,8 +151,7 @@ namespace Emby.Server.Implementations.FileOrganization /// The extensions. private void DeleteLeftOverFiles(string path, IEnumerable extensions) { - var eligibleFiles = _fileSystem.GetFiles(path, true) - .Where(i => extensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase)) + var eligibleFiles = _fileSystem.GetFiles(path, extensions.ToArray(), false, true) .ToList(); foreach (var file in eligibleFiles) diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 026486efc8..17e6786153 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -448,7 +448,7 @@ namespace Emby.Server.Implementations.Library if (parent != null) { - await parent.ValidateChildren(new Progress(), CancellationToken.None, new MetadataRefreshOptions(_fileSystem), false) .ConfigureAwait(false); + await parent.ValidateChildren(new Progress(), CancellationToken.None, new MetadataRefreshOptions(_fileSystem), false).ConfigureAwait(false); } } else if (parent != null) @@ -941,7 +941,7 @@ namespace Emby.Server.Implementations.Library return CreateItemByName(MusicArtist.GetPath, name); } - private T CreateItemByName(Func getPathFn, string name) + private T CreateItemByName(Func getPathFn, string name) where T : BaseItem, new() { if (typeof(T) == typeof(MusicArtist)) @@ -1255,8 +1255,7 @@ namespace Emby.Server.Implementations.Library private string GetCollectionType(string path) { - return _fileSystem.GetFiles(path, false) - .Where(i => string.Equals(i.Extension, ".collection", StringComparison.OrdinalIgnoreCase)) + return _fileSystem.GetFiles(path, new[] { ".collection" }, true, false) .Select(i => _fileSystem.GetFileNameWithoutExtension(i)) .FirstOrDefault(); } @@ -2474,29 +2473,36 @@ namespace Emby.Server.Implementations.Library return GetNamingOptions(new LibraryOptions()); } + private NamingOptions _namingOptions; + private string[] _videoFileExtensions; public NamingOptions GetNamingOptions(LibraryOptions libraryOptions) { - var options = new ExtendedNamingOptions(); + if (_namingOptions == null) + { + var options = new ExtendedNamingOptions(); - // These cause apps to have problems - options.AudioFileExtensions.Remove(".m3u"); - options.AudioFileExtensions.Remove(".wpl"); + // These cause apps to have problems + options.AudioFileExtensions.Remove(".m3u"); + options.AudioFileExtensions.Remove(".wpl"); - if (!libraryOptions.EnableArchiveMediaFiles) - { - options.AudioFileExtensions.Remove(".rar"); - options.AudioFileExtensions.Remove(".zip"); - } + //if (!libraryOptions.EnableArchiveMediaFiles) + { + options.AudioFileExtensions.Remove(".rar"); + options.AudioFileExtensions.Remove(".zip"); + } - if (!libraryOptions.EnableArchiveMediaFiles) - { - options.VideoFileExtensions.Remove(".rar"); - options.VideoFileExtensions.Remove(".zip"); - } + //if (!libraryOptions.EnableArchiveMediaFiles) + { + options.VideoFileExtensions.Remove(".rar"); + options.VideoFileExtensions.Remove(".zip"); + } - options.VideoFileExtensions.Add(".tp"); + options.VideoFileExtensions.Add(".tp"); + _namingOptions = options; + _videoFileExtensions = _namingOptions.VideoFileExtensions.ToArray(); + } - return options; + return _namingOptions; } public ItemLookupInfo ParseName(string name) @@ -2515,12 +2521,14 @@ namespace Emby.Server.Implementations.Library public IEnumerable