From eec9e0482525c400e9dc7cb17bc000434adba105 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 13 Feb 2014 00:11:54 -0500 Subject: take photos into the core --- .../Library/LibraryManager.cs | 24 ++++++----- .../Library/Resolvers/Audio/MusicAlbumResolver.cs | 9 ++-- .../Library/Resolvers/Audio/MusicArtistResolver.cs | 4 +- .../Library/Resolvers/Movies/MovieResolver.cs | 15 ++++--- .../Library/Resolvers/PhotoResolver.cs | 50 ++++++++++++++++++++++ 5 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs (limited to 'MediaBrowser.Server.Implementations/Library') diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 735565e25..b42541204 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -462,21 +462,27 @@ namespace MediaBrowser.Server.Implementations.Library return item; } + public BaseItem ResolvePath(FileSystemInfo fileInfo, Folder parent = null) + { + return ResolvePath(fileInfo, new DirectoryService(_logger), parent); + } + /// /// Resolves a path into a BaseItem /// /// The file info. + /// The directory service. /// The parent. /// BaseItem. - /// - public BaseItem ResolvePath(FileSystemInfo fileInfo, Folder parent = null) + /// fileInfo + public BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null) { if (fileInfo == null) { throw new ArgumentNullException("fileInfo"); } - var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, this) + var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, this, directoryService) { Parent = parent, Path = fileInfo.FullName, @@ -497,8 +503,6 @@ namespace MediaBrowser.Server.Implementations.Library // When resolving the root, we need it's grandchildren (children of user views) var flattenFolderDepth = isPhysicalRoot ? 2 : 0; - var directoryService = new DirectoryService(_logger); - var fileSystemDictionary = FileData.GetFilteredFileSystemEntries(directoryService, args.Path, _fileSystem, _logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf); // Need to remove subpaths that may have been resolved from shortcuts @@ -555,9 +559,10 @@ namespace MediaBrowser.Server.Implementations.Library /// /// /// The files. + /// The directory service. /// The parent. /// List{``0}. - public List ResolvePaths(IEnumerable files, Folder parent) + public List ResolvePaths(IEnumerable files, IDirectoryService directoryService, Folder parent) where T : BaseItem { var list = new List(); @@ -566,7 +571,7 @@ namespace MediaBrowser.Server.Implementations.Library { try { - var item = ResolvePath(f, parent) as T; + var item = ResolvePath(f, directoryService, parent) as T; if (item != null) { @@ -594,10 +599,7 @@ namespace MediaBrowser.Server.Implementations.Library { var rootFolderPath = ConfigurationManager.ApplicationPaths.RootFolderPath; - if (!Directory.Exists(rootFolderPath)) - { - Directory.CreateDirectory(rootFolderPath); - } + Directory.CreateDirectory(rootFolderPath); var rootFolder = RetrieveItem(rootFolderPath.GetMBId(typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(new DirectoryInfo(rootFolderPath)); diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index f6fd11960..7e643cd99 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using System; @@ -62,14 +63,17 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio /// Determine if the supplied file data points to a music album /// /// The path. + /// The directory service. /// true if [is music album] [the specified data]; otherwise, false. - public static bool IsMusicAlbum(string path) + public static bool IsMusicAlbum(string path, IDirectoryService directoryService) { // If list contains at least 2 audio files or at least one and no video files consider it to contain music var foundAudio = 0; - foreach (var fullName in Directory.EnumerateFiles(path)) + foreach (var file in directoryService.GetFiles(path)) { + var fullName = file.FullName; + if (EntityResolutionHelper.IsAudioFile(fullName)) { // Don't resolve these into audio files @@ -105,7 +109,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio if (ContainsMusic(args.FileSystemChildren)) return true; } - return false; } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs index 54a32c367..4fa97fc9d 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs @@ -57,9 +57,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { return null; } + + var directoryService = args.DirectoryService; // If we contain an album assume we are an artist folder - return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName)) ? new MusicArtist() : null; + return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName, directoryService)) ? new MusicArtist() : null; } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index f355f4bf6..2d4540713 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using System; @@ -92,31 +93,31 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1 || string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase)) { - return FindMovie(args.Path, args.Parent, args.FileSystemChildren); + return FindMovie(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService); } if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1 || string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie(args.Path, args.Parent, args.FileSystemChildren); + return FindMovie(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService); } if (args.Path.IndexOf("[adultvideos]", StringComparison.OrdinalIgnoreCase) != -1 || string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie(args.Path, args.Parent, args.FileSystemChildren); + return FindMovie(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService); } if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie