diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs index 79b2651d5a..17520ba1c4 100644 --- a/MediaBrowser.Api/Library/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -75,15 +75,7 @@ namespace MediaBrowser.Api.Library if (locationType != LocationType.Remote && locationType != LocationType.Virtual) { - try - { - return c.PhysicalLocations; - } - catch (Exception ex) - { - Logger.ErrorException("Error getting ResolveArgs for {0}", ex, c.Path); - } - + return c.PhysicalLocations; } return new List(); diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/LibraryService.cs index 584bbf9a1a..a7a58dbfb4 100644 --- a/MediaBrowser.Api/LibraryService.cs +++ b/MediaBrowser.Api/LibraryService.cs @@ -331,21 +331,8 @@ namespace MediaBrowser.Api { if (item.Parent is AggregateFolder) { - return user.RootFolder.GetChildren(user, true).FirstOrDefault(i => - { - - try - { - return i.LocationType == LocationType.FileSystem && - i.PhysicalLocations.Contains(item.Path); - } - catch (Exception ex) - { - Logger.ErrorException("Error getting ResolveArgs for {0}", ex, i.Path); - return false; - } - - }); + return user.RootFolder.GetChildren(user, true).FirstOrDefault(i => i.LocationType == LocationType.FileSystem && + i.PhysicalLocations.Contains(item.Path)); } return item; diff --git a/MediaBrowser.Controller/Entities/AdultVideo.cs b/MediaBrowser.Controller/Entities/AdultVideo.cs index f81cfa1f62..475d7bc54d 100644 --- a/MediaBrowser.Controller/Entities/AdultVideo.cs +++ b/MediaBrowser.Controller/Entities/AdultVideo.cs @@ -3,6 +3,10 @@ namespace MediaBrowser.Controller.Entities { public class AdultVideo : Video, IHasPreferredMetadataLanguage { + /// + /// Gets or sets the preferred metadata language. + /// + /// The preferred metadata language. public string PreferredMetadataLanguage { get; set; } /// diff --git a/MediaBrowser.Controller/Entities/AggregateFolder.cs b/MediaBrowser.Controller/Entities/AggregateFolder.cs index 302842e7e8..ef455846e7 100644 --- a/MediaBrowser.Controller/Entities/AggregateFolder.cs +++ b/MediaBrowser.Controller/Entities/AggregateFolder.cs @@ -1,7 +1,11 @@ -using System; +using MediaBrowser.Controller.IO; +using MediaBrowser.Controller.Library; +using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Runtime.Serialization; namespace MediaBrowser.Controller.Entities { @@ -11,6 +15,11 @@ namespace MediaBrowser.Controller.Entities /// public class AggregateFolder : Folder { + public AggregateFolder() + { + PhysicalLocationsList = new List(); + } + /// /// We don't support manual shortcuts /// @@ -36,6 +45,60 @@ namespace MediaBrowser.Controller.Entities get { return _virtualChildren; } } + [IgnoreDataMember] + public override IEnumerable PhysicalLocations + { + get + { + return PhysicalLocationsList; + } + } + + public List PhysicalLocationsList { get; set; } + + protected override IEnumerable GetFileSystemChildren() + { + return CreateResolveArgs().FileSystemChildren; + } + + private ItemResolveArgs CreateResolveArgs() + { + var path = ContainingFolderPath; + + var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, LibraryManager) + { + FileInfo = new DirectoryInfo(path), + Path = path, + Parent = Parent + }; + + // Gather child folder and files + if (args.IsDirectory) + { + var isPhysicalRoot = args.IsPhysicalRoot; + + // When resolving the root, we need it's grandchildren (children of user views) + var flattenFolderDepth = isPhysicalRoot ? 2 : 0; + + var fileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, FileSystem, Logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf); + + // Need to remove subpaths that may have been resolved from shortcuts + // Example: if \\server\movies exists, then strip out \\server\movies\action + if (isPhysicalRoot) + { + var paths = LibraryManager.NormalizeRootPathList(fileSystemDictionary.Keys); + + fileSystemDictionary = paths.Select(i => (FileSystemInfo)new DirectoryInfo(i)).ToDictionary(i => i.FullName); + } + + args.FileSystemDictionary = fileSystemDictionary; + } + + PhysicalLocationsList = args.PhysicalLocations.ToList(); + + return args; + } + /// /// Adds the virtual child. /// diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 650a9bad09..de5516e299 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1,12 +1,10 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Providers; -using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; @@ -102,6 +100,35 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] protected internal bool IsOffline { get; set; } + /// + /// Returns the folder containing the item. + /// If the item is a folder, it returns the folder itself + /// + [IgnoreDataMember] + public virtual string ContainingFolderPath + { + get + { + if (IsFolder) + { + return Path; + } + + return System.IO.Path.GetDirectoryName(Path); + } + } + + [IgnoreDataMember] + public bool IsOwnedItem + { + get + { + // Local trailer, special feature, theme video, etc. + // An item that belongs to another item but is not part of the Parent-Child tree + return !IsFolder && Parent == null; + } + } + /// /// Gets or sets the type of the location. /// @@ -189,19 +216,6 @@ namespace MediaBrowser.Controller.Entities /// The locked fields. public List LockedFields { get; set; } - /// - /// Should be overridden to return the proper folder where metadata lives - /// - /// The meta location. - [IgnoreDataMember] - public virtual string MetaLocation - { - get - { - return Path ?? ""; - } - } - /// /// Gets the type of the media. /// @@ -215,160 +229,19 @@ namespace MediaBrowser.Controller.Entities } } - /// - /// The _resolve args - /// - private ItemResolveArgs _resolveArgs; - /// - /// We attach these to the item so that we only ever have to hit the file system once - /// (this includes the children of the containing folder) - /// - /// The resolve args. [IgnoreDataMember] - public ItemResolveArgs ResolveArgs + public virtual IEnumerable PhysicalLocations { get { - if (_resolveArgs == null) - { - try - { - _resolveArgs = CreateResolveArgs(); - } - catch (IOException ex) - { - Logger.ErrorException("Error creating resolve args for {0}", ex, Path); - - IsOffline = true; + var locationType = LocationType; - throw; - } - } - - return _resolveArgs; - } - set - { - _resolveArgs = value; - } - } - - [IgnoreDataMember] - public IEnumerable PhysicalLocations - { - get - { - return ResolveArgs.PhysicalLocations; - } - } - - /// - /// Resets the resolve args. - /// - /// The path info. - public void ResetResolveArgs(FileSystemInfo pathInfo) - { - ResetResolveArgs(CreateResolveArgs(pathInfo)); - } - - /// - /// Resets the resolve args. - /// - public void ResetResolveArgs() - { - _resolveArgs = null; - } - - /// - /// Resets the resolve args. - /// - /// The args. - public void ResetResolveArgs(ItemResolveArgs args) - { - _resolveArgs = args; - } - - /// - /// Creates ResolveArgs on demand - /// - /// The path info. - /// ItemResolveArgs. - /// Unable to retrieve file system info for + path - protected internal virtual ItemResolveArgs CreateResolveArgs(FileSystemInfo pathInfo = null) - { - var path = Path; - - var locationType = LocationType; - - if (locationType == LocationType.Remote || - locationType == LocationType.Virtual) - { - return new ItemResolveArgs(ConfigurationManager.ApplicationPaths, LibraryManager); - } - - var isDirectory = false; - - if (UseParentPathToCreateResolveArgs) - { - path = System.IO.Path.GetDirectoryName(path); - isDirectory = true; - } - - pathInfo = pathInfo ?? (isDirectory ? new DirectoryInfo(path) : FileSystem.GetFileSystemInfo(path)); - - if (pathInfo == null || !pathInfo.Exists) - { - throw new IOException("Unable to retrieve file system info for " + path); - } - - var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, LibraryManager) - { - FileInfo = pathInfo, - Path = path, - Parent = Parent - }; - - // Gather child folder and files - if (args.IsDirectory) - { - var isPhysicalRoot = args.IsPhysicalRoot; - - // When resolving the root, we need it's grandchildren (children of user views) - var flattenFolderDepth = isPhysicalRoot ? 2 : 0; - - var fileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, FileSystem, Logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf); - - // Need to remove subpaths that may have been resolved from shortcuts - // Example: if \\server\movies exists, then strip out \\server\movies\action - if (isPhysicalRoot) + if (locationType != LocationType.Remote && locationType != LocationType.Virtual) { - var paths = LibraryManager.NormalizeRootPathList(fileSystemDictionary.Keys); - - fileSystemDictionary = paths.Select(i => (FileSystemInfo)new DirectoryInfo(i)).ToDictionary(i => i.FullName); + return new string[] { }; } - args.FileSystemDictionary = fileSystemDictionary; - } - - //update our dates - EntityResolutionHelper.EnsureDates(FileSystem, this, args, false); - - IsOffline = false; - - return args; - } - - /// - /// Some subclasses will stop resolving at a directory and point their Path to a file within. This will help ensure the on-demand resolve args are identical to the - /// original ones. - /// - /// true if [use parent path to create resolve args]; otherwise, false. - [IgnoreDataMember] - protected virtual bool UseParentPathToCreateResolveArgs - { - get - { - return false; + return new[] { Path }; } } @@ -583,122 +456,93 @@ namespace MediaBrowser.Controller.Entities /// Loads local trailers from the file system /// /// List{Video}. - private IEnumerable LoadLocalTrailers() - { - ItemResolveArgs resolveArgs; - - try - { - resolveArgs = ResolveArgs; - - if (!resolveArgs.IsDirectory) - { - return new List(); - } - } - catch (IOException ex) - { - Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path); - return new List(); - } - - var files = new List(); - - var folder = resolveArgs.GetFileSystemEntryByName(TrailerFolderName); - - // Path doesn't exist. No biggie - if (folder != null) - { - try - { - files.AddRange(new DirectoryInfo(folder.FullName).EnumerateFiles()); - } - catch (IOException ex) - { - Logger.ErrorException("Error loading trailers for {0}", ex, Name); - } - } - - // Support xbmc trailers (-trailer suffix on video file names) - files.AddRange(resolveArgs.FileSystemChildren.Where(i => - { - try - { - if ((i.Attributes & FileAttributes.Directory) != FileAttributes.Directory) - { - if (System.IO.Path.GetFileNameWithoutExtension(i.Name).EndsWith(XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase) && !string.Equals(Path, i.FullName, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - } - } - catch (IOException ex) - { - Logger.ErrorException("Error accessing path {0}", ex, i.FullName); - } - - return false; - })); - - return LibraryManager.ResolvePaths(files, null).Select(video => - { - // Try to retrieve it from the db. If we don't find it, use the resolved version - var dbItem = LibraryManager.GetItemById(video.Id) as Trailer; - - if (dbItem != null) - { - dbItem.ResetResolveArgs(video.ResolveArgs); - video = dbItem; - } - - return video; - - }).ToList(); + private IEnumerable LoadLocalTrailers(List fileSystemChildren) + { + return new List(); + //ItemResolveArgs resolveArgs; + + //try + //{ + // resolveArgs = ResolveArgs; + + // if (!resolveArgs.IsDirectory) + // { + // return new List(); + // } + //} + //catch (IOException ex) + //{ + // Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path); + // return new List(); + //} + + //var files = new List(); + + //var folder = resolveArgs.GetFileSystemEntryByName(TrailerFolderName); + + //// Path doesn't exist. No biggie + //if (folder != null) + //{ + // try + // { + // files.AddRange(new DirectoryInfo(folder.FullName).EnumerateFiles()); + // } + // catch (IOException ex) + // { + // Logger.ErrorException("Error loading trailers for {0}", ex, Name); + // } + //} + + //// Support xbmc trailers (-trailer suffix on video file names) + //files.AddRange(resolveArgs.FileSystemChildren.Where(i => + //{ + // try + // { + // if ((i.Attributes & FileAttributes.Directory) != FileAttributes.Directory) + // { + // if (System.IO.Path.GetFileNameWithoutExtension(i.Name).EndsWith(XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase) && !string.Equals(Path, i.FullName, StringComparison.OrdinalIgnoreCase)) + // { + // return true; + // } + // } + // } + // catch (IOException ex) + // { + // Logger.ErrorException("Error accessing path {0}", ex, i.FullName); + // } + + // return false; + //})); + + //return LibraryManager.ResolvePaths(files, null).Select(video => + //{ + // // Try to retrieve it from the db. If we don't find it, use the resolved version + // var dbItem = LibraryManager.GetItemById(video.Id) as Trailer; + + // if (dbItem != null) + // { + // video = dbItem; + // } + + // return video; + + //}).ToList(); } /// /// Loads the theme songs. /// /// List{Audio.Audio}. - private IEnumerable LoadThemeSongs() + private IEnumerable LoadThemeSongs(List fileSystemChildren) { - ItemResolveArgs resolveArgs; - - try - { - resolveArgs = ResolveArgs; - - if (!resolveArgs.IsDirectory) - { - return new List(); - } - } - catch (IOException ex) - { - Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path); - return new List(); - } - - var files = new List(); - - var folder = resolveArgs.GetFileSystemEntryByName(ThemeSongsFolderName); - - // Path doesn't exist. No biggie - if (folder != null) - { - try - { - files.AddRange(new DirectoryInfo(folder.FullName).EnumerateFiles()); - } - catch (IOException ex) - { - Logger.ErrorException("Error loading theme songs for {0}", ex, Name); - } - } + var files = fileSystemChildren.OfType() + .Where(i => string.Equals(i.Name, ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) + .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly)) + .ToList(); // Support plex/xbmc convention - files.AddRange(resolveArgs.FileSystemChildren - .Where(i => string.Equals(System.IO.Path.GetFileNameWithoutExtension(i.Name), ThemeSongFilename, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsAudioFile(i.Name)) + files.AddRange(fileSystemChildren.OfType() + .Where(i => string.Equals(System.IO.Path.GetFileNameWithoutExtension(i.Name), ThemeSongFilename, StringComparison.OrdinalIgnoreCase)) ); return LibraryManager.ResolvePaths(files, null).Select(audio => @@ -708,7 +552,6 @@ namespace MediaBrowser.Controller.Entities if (dbItem != null) { - dbItem.ResetResolveArgs(audio.ResolveArgs); audio = dbItem; } @@ -720,44 +563,11 @@ namespace MediaBrowser.Controller.Entities /// Loads the video backdrops. /// /// List{Video}. - private IEnumerable