diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library')
24 files changed, 988 insertions, 588 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs b/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs index 0fc04c504..7edd9541f 100644 --- a/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs +++ b/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Resolvers; using System; +using System.Collections.Generic; using System.IO; using System.Linq; @@ -16,6 +17,21 @@ namespace MediaBrowser.Server.Implementations.Library private readonly IFileSystem _fileSystem; private readonly ILibraryManager _libraryManager; + /// <summary> + /// Any folder named in this list will be ignored - can be added to at runtime for extensibility + /// </summary> + public static readonly List<string> IgnoreFolders = new List<string> + { + "metadata", + "ps3_update", + "ps3_vprm", + "extrafanart", + "extrathumbs", + ".actors", + ".wd_tv" + + }; + public CoreResolutionIgnoreRule(IFileSystem fileSystem, ILibraryManager libraryManager) { _fileSystem = fileSystem; @@ -64,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.Library if (args.IsDirectory) { // Ignore any folders in our list - if (EntityResolutionHelper.IgnoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase)) + if (IgnoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase)) { return true; } @@ -88,20 +104,6 @@ namespace MediaBrowser.Server.Implementations.Library } else { - if (args.Parent != null) - { - // Don't resolve these into audio files - if (string.Equals(_fileSystem.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && _libraryManager.IsAudioFile(filename)) - { - return true; - } - - if (BaseItem.ExtraSuffixes.Any(i => filename.IndexOf(i.Key, StringComparison.OrdinalIgnoreCase) != -1)) - { - return true; - } - } - // Ignore samples if (filename.IndexOf(".sample.", StringComparison.OrdinalIgnoreCase) != -1) { diff --git a/MediaBrowser.Server.Implementations/Library/EntityResolutionHelper.cs b/MediaBrowser.Server.Implementations/Library/EntityResolutionHelper.cs deleted file mode 100644 index fdb0b35a1..000000000 --- a/MediaBrowser.Server.Implementations/Library/EntityResolutionHelper.cs +++ /dev/null @@ -1,104 +0,0 @@ -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using System; -using System.Collections.Generic; -using System.IO; - -namespace MediaBrowser.Server.Implementations.Library -{ - /// <summary> - /// Class EntityResolutionHelper - /// </summary> - public static class EntityResolutionHelper - { - /// <summary> - /// Any folder named in this list will be ignored - can be added to at runtime for extensibility - /// </summary> - public static readonly List<string> IgnoreFolders = new List<string> - { - "metadata", - "ps3_update", - "ps3_vprm", - "extrafanart", - "extrathumbs", - ".actors", - ".wd_tv" - - }; - - /// <summary> - /// Ensures DateCreated and DateModified have values - /// </summary> - /// <param name="fileSystem">The file system.</param> - /// <param name="item">The item.</param> - /// <param name="args">The args.</param> - /// <param name="includeCreationTime">if set to <c>true</c> [include creation time].</param> - public static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args, bool includeCreationTime) - { - if (fileSystem == null) - { - throw new ArgumentNullException("fileSystem"); - } - if (item == null) - { - throw new ArgumentNullException("item"); - } - if (args == null) - { - throw new ArgumentNullException("args"); - } - - // See if a different path came out of the resolver than what went in - if (!string.Equals(args.Path, item.Path, StringComparison.OrdinalIgnoreCase)) - { - var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null; - - if (childData != null) - { - if (includeCreationTime) - { - SetDateCreated(item, fileSystem, childData); - } - - item.DateModified = fileSystem.GetLastWriteTimeUtc(childData); - } - else - { - var fileData = fileSystem.GetFileSystemInfo(item.Path); - - if (fileData.Exists) - { - if (includeCreationTime) - { - SetDateCreated(item, fileSystem, fileData); - } - item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData); - } - } - } - else - { - if (includeCreationTime) - { - SetDateCreated(item, fileSystem, args.FileInfo); - } - item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo); - } - } - - private static void SetDateCreated(BaseItem item, IFileSystem fileSystem, FileSystemInfo info) - { - var config = BaseItem.ConfigurationManager.GetMetadataConfiguration(); - - if (config.UseFileCreationTimeForDateAdded) - { - item.DateCreated = fileSystem.GetCreationTimeUtc(info); - } - else - { - item.DateCreated = DateTime.UtcNow; - } - } - } -} diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 63ced8559..bfdfc03ba 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -466,29 +466,54 @@ namespace MediaBrowser.Server.Implementations.Library /// </summary> /// <param name="args">The args.</param> /// <returns>BaseItem.</returns> - public BaseItem ResolveItem(ItemResolveArgs args) + private BaseItem ResolveItem(ItemResolveArgs args) { - var item = EntityResolvers.Select(r => + var item = EntityResolvers.Select(r => Resolve(args, r)) + .FirstOrDefault(i => i != null); + + if (item != null) { - try - { - return r.ResolvePath(args); - } - catch (Exception ex) - { - _logger.ErrorException("Error in {0} resolving {1}", ex, r.GetType().Name, args.Path); + ResolverHelper.SetInitialItemValues(item, args, _fileSystem, this); + } - return null; - } + return item; + } - }).FirstOrDefault(i => i != null); + private BaseItem Resolve(ItemResolveArgs args, IItemResolver resolver) + { + try + { + return resolver.ResolvePath(args); + } + catch (Exception ex) + { + _logger.ErrorException("Error in {0} resolving {1}", ex, resolver.GetType().Name, args.Path); + return null; + } + } - if (item != null) + public Guid GetNewItemId(string key, Type type) + { + if (string.IsNullOrWhiteSpace(key)) + { + throw new ArgumentNullException("key"); + } + if (type == null) { - ResolverHelper.SetInitialItemValues(item, args, _fileSystem); + throw new ArgumentNullException("type"); } - return item; + if (ConfigurationManager.Configuration.EnableLocalizedGuids && key.StartsWith(ConfigurationManager.ApplicationPaths.ProgramDataPath)) + { + // Try to normalize paths located underneath program-data in an attempt to make them more portable + key = key.Substring(ConfigurationManager.ApplicationPaths.ProgramDataPath.Length) + .TrimStart(new[] { '/', '\\' }) + .Replace("/", "\\"); + } + + key = type.FullName + key.ToLower(); + + return key.GetMD5(); } public IEnumerable<BaseItem> ReplaceVideosWithPrimaryVersions(IEnumerable<BaseItem> items) @@ -541,7 +566,7 @@ namespace MediaBrowser.Server.Implementations.Library return ResolvePath(fileInfo, new DirectoryService(_logger), parent, collectionType); } - public BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null, string collectionType = null) + private BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null, string collectionType = null) { if (fileInfo == null) { @@ -621,23 +646,50 @@ namespace MediaBrowser.Server.Implementations.Library return !args.ContainsFileSystemEntryByName(".ignore"); } - public List<T> ResolvePaths<T>(IEnumerable<FileSystemInfo> files, IDirectoryService directoryService, Folder parent, string collectionType = null) - where T : BaseItem + public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemInfo> files, IDirectoryService directoryService, Folder parent, string collectionType) { - return files.Select(f => + var fileList = files.ToList(); + + if (parent != null) + { + var multiItemResolvers = EntityResolvers.OfType<IMultiItemResolver>(); + + foreach (var resolver in multiItemResolvers) + { + var result = resolver.ResolveMultiple(parent, fileList, collectionType, directoryService); + + if (result != null && result.Items.Count > 0) + { + var items = new List<BaseItem>(); + items.AddRange(result.Items); + + foreach (var item in items) + { + ResolverHelper.SetInitialItemValues(item, parent, _fileSystem, this, directoryService); + } + items.AddRange(ResolveFileList(result.ExtraFiles, directoryService, parent, collectionType)); + return items; + } + } + } + + return ResolveFileList(fileList, directoryService, parent, collectionType); + } + + private IEnumerable<BaseItem> ResolveFileList(IEnumerable<FileSystemInfo> fileList, IDirectoryService directoryService, Folder parent, string collectionType) + { + return fileList.Select(f => { try { - return ResolvePath(f, directoryService, parent, collectionType) as T; + return ResolvePath(f, directoryService, parent, collectionType); } catch (Exception ex) { _logger.ErrorException("Error resolving path {0}", ex, f.FullName); return null; } - - }).Where(i => i != null) - .ToList(); + }).Where(i => i != null); } /// <summary> @@ -651,7 +703,7 @@ namespace MediaBrowser.Server.Implementations.Library Directory.CreateDirectory(rootFolderPath); - var rootFolder = GetItemById(rootFolderPath.GetMBId(typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(new DirectoryInfo(rootFolderPath)); + var rootFolder = GetItemById(GetNewItemId(rootFolderPath, typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(new DirectoryInfo(rootFolderPath)); // Add in the plug-in folders foreach (var child in PluginFolderCreators) @@ -662,7 +714,14 @@ namespace MediaBrowser.Server.Implementations.Library { if (folder.Id == Guid.Empty) { - folder.Id = (folder.Path ?? folder.GetType().Name).GetMBId(folder.GetType()); + if (string.IsNullOrWhiteSpace(folder.Path)) + { + folder.Id = GetNewItemId(folder.GetType().Name, folder.GetType()); + } + else + { + folder.Id = GetNewItemId(folder.Path, folder.GetType()); + } } folder = GetItemById(folder.Id) as BasePluginFolder ?? folder; @@ -677,16 +736,27 @@ namespace MediaBrowser.Server.Implementations.Library } private UserRootFolder _userRootFolder; + private readonly object _syncLock = new object(); public Folder GetUserRootFolder() { if (_userRootFolder == null) { - var userRootPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; + lock (_syncLock) + { + if (_userRootFolder == null) + { + var userRootPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; + + Directory.CreateDirectory(userRootPath); - Directory.CreateDirectory(userRootPath); + _userRootFolder = GetItemById(GetNewItemId(userRootPath, typeof(UserRootFolder))) as UserRootFolder; - _userRootFolder = GetItemById(userRootPath.GetMBId(typeof(UserRootFolder))) as UserRootFolder ?? - (UserRootFolder)ResolvePath(new DirectoryInfo(userRootPath)); + if (_userRootFolder == null) + { + _userRootFolder = (UserRootFolder)ResolvePath(new DirectoryInfo(userRootPath)); + } + } + } } return _userRootFolder; @@ -801,7 +871,7 @@ namespace MediaBrowser.Server.Implementations.Library Path.Combine(path, validFilename) : Path.Combine(path, subFolderPrefix, validFilename); - var id = fullPath.GetMBId(type); + var id = GetNewItemId(fullPath, type); BaseItem obj; @@ -1513,7 +1583,7 @@ namespace MediaBrowser.Server.Implementations.Library path = Path.Combine(path, _fileSystem.GetValidFilename(type)); - var id = (path + "_namedview_" + name).GetMBId(typeof(UserView)); + var id = GetNewItemId(path + "_namedview_" + name, typeof(UserView)); var item = GetItemById(id) as UserView; @@ -1578,7 +1648,7 @@ namespace MediaBrowser.Server.Implementations.Library throw new ArgumentNullException("viewType"); } - var id = ("7_namedview_" + name + user.Id.ToString("N") + parentId).GetMBId(typeof(UserView)); + var id = GetNewItemId("7_namedview_" + name + user.Id.ToString("N") + parentId, typeof(UserView)); var path = BaseItem.GetInternalMetadataPathForId(id); @@ -1670,41 +1740,132 @@ namespace MediaBrowser.Server.Implementations.Library }; } - public IEnumerable<FileSystemInfo> GetAdditionalParts(string file, - VideoType type, - IEnumerable<FileSystemInfo> files) + public IEnumerable<Video> FindTrailers(BaseItem owner, List<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService) { - var resolver = new StackResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); + var files = fileSystemChildren.OfType<DirectoryInfo>() + .Where(i => string.Equals(i.Name, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase)) + .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly)) + .ToList(); - StackResult result; - List<FileSystemInfo> filteredFiles; + var videoListResolver = new VideoListResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); - if (type == VideoType.BluRay || type == VideoType.Dvd) + var videos = videoListResolver.Resolve(fileSystemChildren.Select(i => new PortableFileInfo { - filteredFiles = files.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory) - .ToList(); + FullName = i.FullName, + Type = GetFileType(i) + + }).ToList()); + + var currentVideo = videos.FirstOrDefault(i => string.Equals(owner.Path, i.Files.First().Path, StringComparison.OrdinalIgnoreCase)); - result = resolver.ResolveDirectories(filteredFiles.Select(i => i.FullName)); + if (currentVideo != null) + { + files.AddRange(currentVideo.Extras.Where(i => string.Equals(i.ExtraType, "trailer", StringComparison.OrdinalIgnoreCase)).Select(i => new FileInfo(i.Path))); } - else + + return ResolvePaths(files, directoryService, null, null) + .OfType<Video>() + .Select(video => { - filteredFiles = files.Where(i => (i.Attributes & FileAttributes.Directory) != FileAttributes.Directory) - .ToList(); + // Try to retrieve it from the db. If we don't find it, use the resolved version + var dbItem = GetItemById(video.Id) as Video; + + if (dbItem != null) + { + video = dbItem; + } + + video.ExtraType = ExtraType.Trailer; - result = resolver.ResolveFiles(filteredFiles.Select(i => i.FullName)); + return video; + + // Sort them so that the list can be easily compared for changes + }).OrderBy(i => i.Path).ToList(); + } + + private FileInfoType GetFileType(FileSystemInfo info) + { + if ((info.Attributes & FileAttributes.Directory) == FileAttributes.Directory) + { + return FileInfoType.Directory; } - var stack = result.Stacks - .FirstOrDefault(i => i.Files.Contains(file, StringComparer.OrdinalIgnoreCase)); + return FileInfoType.File; + } - if (stack != null) + public IEnumerable<Video> FindExtras(BaseItem owner, List<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService) + { + var files = fileSystemChildren.OfType<DirectoryInfo>() + .Where(i => string.Equals(i.Name, "extras", StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, "specials", StringComparison.OrdinalIgnoreCase)) + .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly)) + .ToList(); + + var videoListResolver = new VideoListResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); + + var videos = videoListResolver.Resolve(fileSystemChildren.Select(i => new PortableFileInfo { - return stack.Files.Where(i => !string.Equals(i, file, StringComparison.OrdinalIgnoreCase)) - .Select(i => filteredFiles.FirstOrDefault(f => string.Equals(i, f.FullName, StringComparison.OrdinalIgnoreCase))) - .Where(i => i != null); + FullName = i.FullName, + Type = GetFileType(i) + + }).ToList()); + + var currentVideo = videos.FirstOrDefault(i => string.Equals(owner.Path, i.Files.First().Path, StringComparison.OrdinalIgnoreCase)); + + if (currentVideo != null) + { + files.AddRange(currentVideo.Extras.Where(i => !string.Equals(i.ExtraType, "trailer", StringComparison.OrdinalIgnoreCase)).Select(i => new FileInfo(i.Path))); } - return new List<FileSystemInfo>(); + return ResolvePaths(files, directoryService, null, null) + .OfType<Video>() + .Select(video => + { + // Try to retrieve it from the db. If we don't find it, use the resolved version + var dbItem = GetItemById(video.Id) as Video; + + if (dbItem != null) + { + video = dbItem; + } + + SetExtraTypeFromFilename(video); + + return video; + + // Sort them so that the list can be easily compared for changes + }).OrderBy(i => i.Path).ToList(); + } + + private void SetExtraTypeFromFilename(Video item) + { + var resolver = new ExtraResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger(), new RegexProvider()); + + var result = resolver.GetExtraInfo(item.Path); + + if (string.Equals(result.ExtraType, "deletedscene", StringComparison.OrdinalIgnoreCase)) + { + item.ExtraType = ExtraType.DeletedScene; + } + else if (string.Equals(result.ExtraType, "behindthescenes", StringComparison.OrdinalIgnoreCase)) + { + item.ExtraType = ExtraType.BehindTheScenes; + } + else if (string.Equals(result.ExtraType, "interview", StringComparison.OrdinalIgnoreCase)) + { + item.ExtraType = ExtraType.Interview; + } + else if (string.Equals(result.ExtraType, "scene", StringComparison.OrdinalIgnoreCase)) + { + item.ExtraType = ExtraType.Scene; + } + else if (string.Equals(result.ExtraType, "sample", StringComparison.OrdinalIgnoreCase)) + { + item.ExtraType = ExtraType.Sample; + } + else + { + item.ExtraType = ExtraType.Clip; + } } } } diff --git a/MediaBrowser.Server.Implementations/Library/LocalTrailerPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/LocalTrailerPostScanTask.cs new file mode 100644 index 000000000..9196bf734 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Library/LocalTrailerPostScanTask.cs @@ -0,0 +1,94 @@ +using System.Collections.Generic; +using MediaBrowser.Controller.Channels; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Channels; +using MediaBrowser.Model.Entities; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Server.Implementations.Library +{ + public class LocalTrailerPostScanTask : ILibraryPostScanTask + { + private readonly ILibraryManager _libraryManager; + private readonly IChannelManager _channelManager; + + public LocalTrailerPostScanTask(ILibraryManager libraryManager, IChannelManager channelManager) + { + _libraryManager = libraryManager; + _channelManager = channelManager; + } + + public async Task Run(IProgress<double> progress, CancellationToken cancellationToken) + { + var items = _libraryManager.RootFolder + .RecursiveChildren + .OfType<IHasTrailers>() + .ToList(); + + var channelTrailerResult = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery + { + ExtraTypes = new[] { ExtraType.Trailer } + + }, CancellationToken.None); + var channelTrailers = channelTrailerResult.Items; + + var numComplete = 0; + + foreach (var item in items) + { + cancellationToken.ThrowIfCancellationRequested(); + + await AssignTrailers(item, channelTrailers).ConfigureAwait(false); + + numComplete++; + double percent = numComplete; + percent /= items.Count; + progress.Report(percent * 100); + } + + progress.Report(100); + } + + private async Task AssignTrailers(IHasTrailers item, BaseItem[] channelTrailers) + { + if (item is Game) + { + return; + } + + var imdbId = item.GetProviderId(MetadataProviders.Imdb); + var tmdbId = item.GetProviderId(MetadataProviders.Tmdb); + + var trailers = channelTrailers.Where(i => + { + if (!string.IsNullOrWhiteSpace(imdbId) && + string.Equals(imdbId, i.GetProviderId(MetadataProviders.Imdb), StringComparison.OrdinalIgnoreCase)) + { + return true; + } + if (!string.IsNullOrWhiteSpace(tmdbId) && + string.Equals(tmdbId, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase)) + { + return true; + } + return false; + }); + + var trailerIds = trailers.Select(i => i.Id) + .ToList(); + + if (!trailerIds.SequenceEqual(item.RemoteTrailerIds)) + { + item.RemoteTrailerIds = trailerIds; + + var baseItem = (BaseItem)item; + await baseItem.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None) + .ConfigureAwait(false); + } + } + } +} diff --git a/MediaBrowser.Server.Implementations/Library/MusicManager.cs b/MediaBrowser.Server.Implementations/Library/MusicManager.cs index 7ffbab860..b8c29c19b 100644 --- a/MediaBrowser.Server.Implementations/Library/MusicManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MusicManager.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Playlists; using System; using System.Collections.Generic; using System.Linq; @@ -53,6 +54,18 @@ namespace MediaBrowser.Server.Implementations.Library return GetInstantMixFromGenres(genres, user); } + public IEnumerable<Audio> GetInstantMixFromPlaylist(Playlist item, User user) + { + var genres = item + .GetRecursiveChildren(user, true) + .OfType<Audio>() + .SelectMany(i => i.Genres) + .Concat(item.Genres) + .Distinct(StringComparer.OrdinalIgnoreCase); + + return GetInstantMixFromGenres(genres, user); + } + public IEnumerable<Audio> GetInstantMixFromGenres(IEnumerable<string> genres, User user) { var inputItems = user.RootFolder.GetRecursiveChildren(user); diff --git a/MediaBrowser.Server.Implementations/Library/PathExtensions.cs b/MediaBrowser.Server.Implementations/Library/PathExtensions.cs new file mode 100644 index 000000000..00bd65125 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Library/PathExtensions.cs @@ -0,0 +1,37 @@ +using System; + +namespace MediaBrowser.Server.Implementations.Library +{ + public static class PathExtensions + { + /// <summary> + /// Gets the attribute value. + /// </summary> + /// <param name="str">The STR.</param> + /// <param name="attrib">The attrib.</param> + /// <returns>System.String.</returns> + /// <exception cref="System.ArgumentNullException">attrib</exception> + public static string GetAttributeValue(this string str, string attrib) + { + if (string.IsNullOrEmpty(str)) + { + throw new ArgumentNullException("str"); + } + + if (string.IsNullOrEmpty(attrib)) + { + throw new ArgumentNullException("attrib"); + } + + string srch = "[" + attrib + "="; + int start = str.IndexOf(srch, StringComparison.OrdinalIgnoreCase); + if (start > -1) + { + start += srch.Length; + int end = str.IndexOf(']', start); + return str.Substring(start, end - start); + } + return null; + } + } +} diff --git a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs index b9fbd6f8c..03e28d7ba 100644 --- a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs +++ b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs @@ -1,7 +1,7 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.IO; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; using System; using System.IO; using System.Linq; @@ -18,9 +18,52 @@ namespace MediaBrowser.Server.Implementations.Library /// Sets the initial item values. /// </summary> /// <param name="item">The item.</param> + /// <param name="parent">The parent.</param> + /// <param name="fileSystem">The file system.</param> + /// <param name="libraryManager">The library manager.</param> + /// <param name="directoryService">The directory service.</param> + /// <exception cref="System.ArgumentException">Item must have a path</exception> + public static void SetInitialItemValues(BaseItem item, Folder parent, IFileSystem fileSystem, ILibraryManager libraryManager, IDirectoryService directoryService) + { + // This version of the below method has no ItemResolveArgs, so we have to require the path already being set + if (string.IsNullOrWhiteSpace(item.Path)) + { + throw new ArgumentException("Item must have a Path"); + } + + // If the resolver didn't specify this + if (parent != null) + { + item.Parent = parent; + } + + item.Id = libraryManager.GetNewItemId(item.Path, item.GetType()); + + // If the resolver didn't specify this + if (string.IsNullOrEmpty(item.DisplayMediaType)) + { + item.DisplayMediaType = item.GetType().Name; + } + + item.IsLocked = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1 || + item.Parents.Any(i => i.IsLocked); + + // Make sure DateCreated and DateModified have values + var fileInfo = directoryService.GetFile(item.Path); + item.DateModified = fileSystem.GetLastWriteTimeUtc(fileInfo); + SetDateCreated(item, fileSystem, fileInfo); + + EnsureName(item, fileInfo); + } + + /// <summary> + /// Sets the initial item values. + /// </summary> + /// <param name="item">The item.</param> /// <param name="args">The args.</param> /// <param name="fileSystem">The file system.</param> - public static void SetInitialItemValues(BaseItem item, ItemResolveArgs args, IFileSystem fileSystem) + /// <param name="libraryManager">The library manager.</param> + public static void SetInitialItemValues(BaseItem item, ItemResolveArgs args, IFileSystem fileSystem, ILibraryManager libraryManager) { // If the resolver didn't specify this if (string.IsNullOrEmpty(item.Path)) @@ -34,7 +77,7 @@ namespace MediaBrowser.Server.Implementations.Library item.Parent = args.Parent; } - item.Id = item.Path.GetMBId(item.GetType()); + item.Id = libraryManager.GetNewItemId(item.Path, item.GetType()); // If the resolver didn't specify this if (string.IsNullOrEmpty(item.DisplayMediaType)) @@ -43,56 +86,123 @@ namespace MediaBrowser.Server.Implementations.Library } // Make sure the item has a name - EnsureName(item, args); + EnsureName(item, args.FileInfo); item.IsLocked = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1 || item.Parents.Any(i => i.IsLocked); // Make sure DateCreated and DateModified have values - EntityResolutionHelper.EnsureDates(fileSystem, item, args, true); + EnsureDates(fileSystem, item, args, true); } /// <summary> /// Ensures the name. /// </summary> /// <param name="item">The item.</param> - private static void EnsureName(BaseItem item, ItemResolveArgs args) + /// <param name="fileInfo">The file information.</param> + private static void EnsureName(BaseItem item, FileSystemInfo fileInfo) { // If the subclass didn't supply a name, add it here if (string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Path)) { - //we use our resolve args name here to get the name of the containg folder, not actual video file - item.Name = GetMbName(args.FileInfo.Name, (args.FileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory); + item.Name = GetDisplayName(fileInfo.Name, (fileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory); } } /// <summary> + /// Gets the display name. + /// </summary> + /// <param name="path">The path.</param> + /// <param name="isDirectory">if set to <c>true</c> [is directory].</param> + /// <returns>System.String.</returns> + private static string GetDisplayName(string path, bool isDirectory) + { + return isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path); + } + + /// <summary> /// The MB name regex /// </summary> private static readonly Regex MbNameRegex = new Regex(@"(\[.*?\])", RegexOptions.Compiled); + internal static string StripBrackets(string inputString) + { + var output = MbNameRegex.Replace(inputString, string.Empty).Trim(); + return Regex.Replace(output, @"\s+", " "); + } + /// <summary> - /// Strip out attribute items and return just the name we will use for items + /// Ensures DateCreated and DateModified have values /// </summary> - /// <param name="path">Assumed to be a file or directory path</param> - /// <param name="isDirectory">if set to <c>true</c> [is directory].</param> - /// <returns>The cleaned name</returns> - private static string GetMbName(string path, bool isDirectory) + /// <param name="fileSystem">The file system.</param> + /// <param name="item">The item.</param> + /// <param name="args">The args.</param> + /// <param name="includeCreationTime">if set to <c>true</c> [include creation time].</param> + private static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args, bool includeCreationTime) { - //first just get the file or directory name - var fn = isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path); + if (fileSystem == null) + { + throw new ArgumentNullException("fileSystem"); + } + if (item == null) + { + throw new ArgumentNullException("item"); + } + if (args == null) + { + throw new ArgumentNullException("args"); + } + + // See if a different path came out of the resolver than what went in + if (!string.Equals(args.Path, item.Path, StringComparison.OrdinalIgnoreCase)) + { + var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null; + + if (childData != null) + { + if (includeCreationTime) + { + SetDateCreated(item, fileSystem, childData); + } - //now - strip out anything inside brackets - fn = StripBrackets(fn); + item.DateModified = fileSystem.GetLastWriteTimeUtc(childData); + } + else + { + var fileData = fileSystem.GetFileSystemInfo(item.Path); - return fn; + if (fileData.Exists) + { + if (includeCreationTime) + { + SetDateCreated(item, fileSystem, fileData); + } + item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData); + } + } + } + else + { + if (includeCreationTime) + { + SetDateCreated(item, fileSystem, args.FileInfo); + } + item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo); + } } - private static string StripBrackets(string inputString) + private static void SetDateCreated(BaseItem item, IFileSystem fileSystem, FileSystemInfo info) { - var output = MbNameRegex.Replace(inputString, string.Empty).Trim(); - return Regex.Replace(output, @"\s+", " "); - } + var config = BaseItem.ConfigurationManager.GetMetadataConfiguration(); + if (config.UseFileCreationTimeForDateAdded) + { + item.DateCreated = fileSystem.GetCreationTimeUtc(info); + } + else + { + item.DateCreated = DateTime.UtcNow; + } + } } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs index 62eb1f47d..b4cda39cd 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs @@ -41,10 +41,19 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { var collectionType = args.GetCollectionType(); + var isMixed = string.IsNullOrWhiteSpace(collectionType); + + // For conflicting extensions, give priority to videos + if (isMixed && _libraryManager.IsVideoFile(args.Path)) + { + return null; + } + var isStandalone = args.Parent == null; if (isStandalone || - string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase)) + string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) || + isMixed) { return new Controller.Entities.Audio.Audio(); } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index 5ba07cdae..7f844ca0e 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -141,12 +141,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio if (libraryManager.IsAudioFile(fullName)) { - // Don't resolve these into audio files - if (string.Equals(fileSystem.GetFileNameWithoutExtension(fullName), BaseItem.ThemeSongFilename)) - { - continue; - } - return true; } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs index 1b4903641..8e2218b0a 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs @@ -1,10 +1,12 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; -using MediaBrowser.Naming.Audio; using MediaBrowser.Naming.Common; using MediaBrowser.Naming.Video; using System; +using System.IO; +using System.Linq; namespace MediaBrowser.Server.Implementations.Library.Resolvers { @@ -29,7 +31,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers /// <returns>`0.</returns> protected override T Resolve(ItemResolveArgs args) { - return ResolveVideo<T>(args); + return ResolveVideo<T>(args, false); } /// <summary> @@ -37,14 +39,93 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers /// </summary> /// <typeparam name="TVideoType">The type of the T video type.</typeparam> /// <param name="args">The args.</param> + /// <param name="parseName">if set to <c>true</c> [parse name].</param> /// <returns>``0.</returns> - protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args) + protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args, bool parseName) where TVideoType : Video, new() { // If the path is a file check for a matching extensions - if (!args.IsDirectory) + var parser = new Naming.Video.VideoResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); + + if (args.IsDirectory) + { + TVideoType video = null; + VideoFileInfo videoInfo = null; + + // Loop through each child file/folder and see if we find a video + foreach (var child in args.FileSystemChildren) + { + var filename = child.Name; + + if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory) + { + if (IsDvdDirectory(filename)) + { + videoInfo = parser.ResolveDirectory(args.Path); + + if (videoInfo == null) + { + return null; + } + + video = new TVideoType + { + Path = args.Path, + VideoType = VideoType.Dvd, + ProductionYear = videoInfo.Year + }; + break; + } + if (IsBluRayDirectory(filename)) + { + videoInfo = parser.ResolveDirectory(args.Path); + + if (videoInfo == null) + { + return null; + } + + video = new TVideoType + { + Path = args.Path, + VideoType = VideoType.BluRay, + ProductionYear = videoInfo.Year + }; + break; + } + } + else if (IsDvdFile(filename)) + { + videoInfo = parser.ResolveDirectory(args.Path); + + if (videoInfo == null) + { + return null; + } + + video = new TVideoType + { + Path = args.Path, + VideoType = VideoType.Dvd, + ProductionYear = videoInfo.Year + }; + break; + } + } + + if (video != null) + { + video.Name = parseName ? + videoInfo.Name : + Path.GetFileName(args.Path); + + Set3DFormat(video, videoInfo); + } + + return video; + } + else { - var parser = new Naming.Video.VideoResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); var videoInfo = parser.ResolveFile(args.Path); if (videoInfo == null) @@ -52,74 +133,24 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers return null; } - var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase); - - if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut) + if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub) { - var type = string.Equals(videoInfo.Container, "iso", StringComparison.OrdinalIgnoreCase) || string.Equals(videoInfo.Container, "img", StringComparison.OrdinalIgnoreCase) ? - VideoType.Iso : - VideoType.VideoFile; - var path = args.Path; var video = new TVideoType { - VideoType = type, Path = path, IsInMixedFolder = true, - IsPlaceHolder = videoInfo.IsStub, - IsShortcut = isShortcut, - Name = videoInfo.Name, ProductionYear = videoInfo.Year }; - if (videoInfo.IsStub) - { - if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase)) - { - video.VideoType = VideoType.Dvd; - } - else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase)) - { - video.VideoType = VideoType.HdDvd; - } - else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase)) - { - video.VideoType = VideoType.BluRay; - } - } + SetVideoType(video, videoInfo); + + video.Name = parseName ? + videoInfo.Name : + Path.GetFileNameWithoutExtension(args.Path); - if (videoInfo.Is3D) - { - if (string.Equals(videoInfo.Format3D, "fsbs", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.FullSideBySide; - } - else if (string.Equals(videoInfo.Format3D, "ftab", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.FullTopAndBottom; - } - else if (string.Equals(videoInfo.Format3D, "hsbs", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfSideBySide; - } - else if (string.Equals(videoInfo.Format3D, "htab", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfTopAndBottom; - } - else if (string.Equals(videoInfo.Format3D, "sbs", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfSideBySide; - } - else if (string.Equals(videoInfo.Format3D, "sbs3d", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfSideBySide; - } - else if (string.Equals(videoInfo.Format3D, "tab", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfTopAndBottom; - } - } + Set3DFormat(video, videoInfo); return video; } @@ -127,5 +158,111 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers return null; } + + protected void SetVideoType(Video video, VideoFileInfo videoInfo) + { + var extension = Path.GetExtension(video.Path); + video.VideoType = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || + string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ? + VideoType.Iso : + VideoType.VideoFile; + + video.IsShortcut = string.Equals(extension, ".strm", StringComparison.OrdinalIgnoreCase); + video.IsPlaceHolder = videoInfo.IsStub; + + if (videoInfo.IsStub) + { + if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase)) + { + video.VideoType = VideoType.Dvd; + } + else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase)) + { + video.VideoType = VideoType.HdDvd; + } + else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase)) + { + video.VideoType = VideoType.BluRay; + } + } + } + + protected void Set3DFormat(Video video, bool is3D, string format3D) + { + if (is3D) + { + if (string.Equals(format3D, "fsbs", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.FullSideBySide; + } + else if (string.Equals(format3D, "ftab", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.FullTopAndBottom; + } + else if (string.Equals(format3D, "hsbs", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfSideBySide; + } + else if (string.Equals(format3D, "htab", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfTopAndBottom; + } + else if (string.Equals(format3D, "sbs", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfSideBySide; + } + else if (string.Equals(format3D, "sbs3d", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfSideBySide; + } + else if (string.Equals(format3D, "tab", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfTopAndBottom; + } + } + } + + protected void Set3DFormat(Video video, VideoFileInfo videoInfo) + { + Set3DFormat(video, videoInfo.Is3D, videoInfo.Format3D); + } + + protected void Set3DFormat(Video video) + { + var resolver = new Format3DParser(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); + var result = resolver.Parse(video.Path); + + Set3DFormat(video, result.Is3D, result.Format3D); + } + + /// <summary> + /// Determines whether [is DVD directory] [the specified directory name]. + /// </summary> + /// <param name="directoryName">Name of the directory.</param> + /// <returns><c>true</c> if [is DVD directory] [the specified directory name]; otherwise, <c>false</c>.</returns> + protected bool IsDvdDirectory(string directoryName) + { + return string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase); + } + + /// <summary> + /// Determines whether [is DVD file] [the specified name]. + /// </summary> + /// <param name="name">The name.</param> + /// <returns><c>true</c> if [is DVD file] [the specified name]; otherwise, <c>false</c>.</returns> + protected bool IsDvdFile(string name) + { + return string.Equals(name, "video_ts.ifo", StringComparison.OrdinalIgnoreCase); + } + + /// <summary> + /// Determines whether [is blu ray directory] [the specified directory name]. + /// </summary> + /// <param name="directoryName">Name of the directory.</param> + /// <returns><c>true</c> if [is blu ray directory] [the specified directory name]; otherwise, <c>false</c>.</returns> + protected bool IsBluRayDirectory(string directoryName) + { + return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase); + } } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs deleted file mode 100644 index dfeefb74f..000000000 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs +++ /dev/null @@ -1,61 +0,0 @@ -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Resolvers; -using MediaBrowser.Model.Entities; -using System; -using System.IO; -using System.Linq; - -namespace MediaBrowser.Server.Implementations.Library.Resolvers -{ - /// <summary> - /// Class LocalTrailerResolver - /// </summary> - public class LocalTrailerResolver : BaseVideoResolver<Trailer> - { - private readonly IFileSystem _fileSystem; - - public LocalTrailerResolver(ILibraryManager libraryManager, IFileSystem fileSystem) : base(libraryManager) - { - _fileSystem = fileSystem; - } - - /// <summary> - /// Resolves the specified args. - /// </summary> - /// <param name="args">The args.</param> - /// <returns>Trailer.</returns> - protected override Trailer Resolve(ItemResolveArgs args) - { - // Trailers are not Children, therefore this can never happen - if (args.Parent != null) - { - return null; - } - - // If the file is within a trailers folder, see if the VideoResolver returns something - if (!args.IsDirectory) - { - if (string.Equals(Path.GetFileName(Path.GetDirectoryName(args.Path)), BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase)) - { - return base.Resolve(args); - } - - // Support xbmc local trailer convention, but only when looking for local trailers (hence the parent == null check) - if (args.Parent == null) - { - var nameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(args.Path); - var suffix = BaseItem.ExtraSuffixes.First(i => i.Value == ExtraType.Trailer); - - if (nameWithoutExtension.EndsWith(suffix.Key, StringComparison.OrdinalIgnoreCase)) - { - return base.Resolve(args); - } - } - } - - return null; - } - } -} diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs index 1416bd04e..cc261c3e7 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Entities; @@ -38,9 +37,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return null; } - if (filename.IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1 || args.ContainsFileSystemEntryByName("collection.xml")) + if (filename.IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1 || + args.ContainsFileSystemEntryByName("collection.xml")) { - return new BoxSet { Path = args.Path }; + return new BoxSet + { + Path = args.Path, + Name = ResolverHelper.StripBrackets(Path.GetFileName(args.Path)) + }; } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index a2da9ff77..9f714cfc5 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -1,33 +1,34 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.IO; +using MediaBrowser.Common.IO; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; 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 MediaBrowser.Model.Logging; +using MediaBrowser.Naming.Common; +using MediaBrowser.Naming.IO; +using MediaBrowser.Naming.Video; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using MediaBrowser.Naming.Audio; -using MediaBrowser.Naming.Common; -using MediaBrowser.Naming.Video; namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { /// <summary> /// Class MovieResolver /// </summary> - public class MovieResolver : BaseVideoResolver<Video> + public class MovieResolver : BaseVideoResolver<Video>, IMultiItemResolver { private readonly IServerApplicationPaths _applicationPaths; private readonly ILogger _logger; private readonly IFileSystem _fileSystem; - public MovieResolver(ILibraryManager libraryManager, IServerApplicationPaths applicationPaths, ILogger logger, IFileSystem fileSystem) : base(libraryManager) + public MovieResolver(ILibraryManager libraryManager, IServerApplicationPaths applicationPaths, ILogger logger, IFileSystem fileSystem) + : base(libraryManager) { _applicationPaths = applicationPaths; _logger = logger; @@ -45,93 +46,189 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies // Give plugins a chance to catch iso's first // Also since we have to loop through child files looking for videos, // see if we can avoid some of that by letting other resolvers claim folders first - return ResolverPriority.Second; + // Also run after series resolver + return ResolverPriority.Third; } } - /// <summary> - /// Resolves the specified args. - /// </summary> - /// <param name="args">The args.</param> - /// <returns>Video.</returns> - protected override Video Resolve(ItemResolveArgs args) + public MultiItemResolverResult ResolveMultiple(Folder parent, + List<FileSystemInfo> files, + string collectionType, + IDirectoryService directoryService) { - // Avoid expensive tests against VF's and all their children by not allowing this - if (args.Parent != null) + if (IsInvalid(parent, collectionType, files)) + { + return null; + } + + if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) + { + return ResolveVideos<MusicVideo>(parent, files, directoryService, collectionType); + } + + if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) + { + return ResolveVideos<Video>(parent, files, directoryService, collectionType); + } + + if (string.IsNullOrEmpty(collectionType)) { - if (args.Parent.IsRoot) + // Owned items should just use the plain video type + if (parent == null) { - return null; + return ResolveVideos<Video>(parent, files, directoryService, collectionType); } + + return ResolveVideos<Movie>(parent, files, directoryService, collectionType); + } + + if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || + string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) + { + return ResolveVideos<Movie>(parent, files, directoryService, collectionType); } - var isDirectory = args.IsDirectory; + return null; + } + + private MultiItemResolverResult ResolveVideos<T>(Folder parent, IEnumerable<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, string collectionType) + where T : Video, new() + { + var files = new List<FileSystemInfo>(); + var videos = new List<BaseItem>(); + var leftOver = new List<FileSystemInfo>(); - if (isDirectory) + // Loop through each child file/folder and see if we find a video + foreach (var child in fileSystemEntries) { - // Since the looping is expensive, this is an optimization to help us avoid it - if (args.ContainsMetaFileByName("series.xml")) + if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory) + { + leftOver.Add(child); + } + else { - return null; + files.Add(child); } } + var resolver = new VideoListResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); + var resolverResult = resolver.Resolve(files.Select(i => new PortableFileInfo + { + FullName = i.FullName, + Type = FileInfoType.File + + }).ToList()).ToList(); + + var result = new MultiItemResolverResult + { + ExtraFiles = leftOver, + Items = videos + }; + + var isInMixedFolder = resolverResult.Count > 0; + + foreach (var video in resolverResult) + { + var firstVideo = video.Files.First(); + + var videoItem = new T + { + Path = video.Files[0].Path, + IsInMixedFolder = isInMixedFolder, + ProductionYear = video.Year, + Name = video.Name, + AdditionalParts = video.Files.Skip(1).Select(i => i.Path).ToList() + }; + + SetVideoType(videoItem, firstVideo); + Set3DFormat(videoItem, firstVideo); + + result.Items.Add(videoItem); + } + + return result; + } + + /// <summary> + /// Resolves the specified args. + /// </summary> + /// <param name="args">The args.</param> + /// <returns>Video.</returns> + protected override Video Resolve(ItemResolveArgs args) + { var collectionType = args.GetCollectionType(); + if (IsInvalid(args.Parent, collectionType, args.FileSystemChildren)) + { + return null; + } + // Find movies with their own folders - if (isDirectory) + if (args.IsDirectory) { - if (string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<Trailer>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false, collectionType); + return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType, false); } - if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false, collectionType); + return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType, false); } - if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) + if (string.IsNullOrEmpty(collectionType)) { - return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, true, false, collectionType); + // Owned items should just use the plain video type + if (args.Parent == null) + { + return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType); + } + + // Since the looping is expensive, this is an optimization to help us avoid it + if (args.ContainsMetaFileByName("series.xml")) + { + return null; + } + + return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType); } - if (string.IsNullOrEmpty(collectionType) || - string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || - string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || + string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, true, true, collectionType); + return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, collectionType); } return null; } - var filename = Path.GetFileName(args.Path); - // Don't misidentify extras or trailers - if (BaseItem.ExtraSuffixes.Any(i => filename.IndexOf(i.Key, StringComparison.OrdinalIgnoreCase) != -1)) + // Owned items will be caught by the plain video resolver + if (args.Parent == null) { return null; } - // Find movies that are mixed in the same folder - if (string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase)) - { - return ResolveVideo<Trailer>(args); - } - Video item = null; if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) { - item = ResolveVideo<MusicVideo>(args); + item = ResolveVideo<MusicVideo>(args, false); } // To find a movie file, the collection type must be movies or boxsets - // Otherwise we'll consider it a plain video and let the video resolver handle it - if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || + else if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) { - item = ResolveVideo<Movie>(args); + item = ResolveVideo<Movie>(args, true); + } + + else if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) + { + item = ResolveVideo<Video>(args, false); + } + else if (string.IsNullOrEmpty(collectionType)) + { + item = ResolveVideo<Movie>(args, false); } if (item != null) @@ -179,16 +276,15 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies /// <param name="parent">The parent.</param> /// <param name="fileSystemEntries">The file system entries.</param> /// <param name="directoryService">The directory service.</param> - /// <param name="supportMultiFileItems">if set to <c>true</c> [support multi file items].</param> + /// <param name="collectionType">Type of the collection.</param> + /// <param name="supportMultiVersion">if set to <c>true</c> [support multi version].</param> /// <returns>Movie.</returns> - private T FindMovie<T>(string path, Folder parent, List<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, bool supportMultiFileItems, bool supportsMultipleSources, string collectionType) + private T FindMovie<T>(string path, Folder parent, List<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, string collectionType, bool supportMultiVersion = true) where T : Video, new() { - var movies = new List<T>(); - var multiDiscFolders = new List<FileSystemInfo>(); - - // Loop through each child file/folder and see if we find a video + + // Search for a folder rip foreach (var child in fileSystemEntries) { var filename = child.Name; @@ -197,78 +293,70 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { if (IsDvdDirectory(filename)) { - return new T + var movie = new T { Path = path, VideoType = VideoType.Dvd }; + Set3DFormat(movie); + return movie; } if (IsBluRayDirectory(filename)) { - return new T + var movie = new T { Path = path, VideoType = VideoType.BluRay }; + Set3DFormat(movie); + return movie; } multiDiscFolders.Add(child); - - continue; } - - // Don't misidentify extras or trailers as a movie - if (BaseItem.ExtraSuffixes.Any(i => filename.IndexOf(i.Key, StringComparison.OrdinalIgnoreCase) != -1)) - { - continue; - } - - var childArgs = new ItemResolveArgs(_applicationPaths, LibraryManager, directoryService) + else if (IsDvdFile(filename)) { - FileInfo = child, - Path = child.FullName, - Parent = parent, - CollectionType = collectionType - }; - - var item = ResolveVideo<T>(childArgs); - - if (item != null) - { - item.IsInMixedFolder = false; - movies.Add(item); + var movie = new T + { + Path = path, + VideoType = VideoType.Dvd + }; + Set3DFormat(movie); + return movie; } } + + var result = ResolveVideos<T>(parent, fileSystemEntries, directoryService, collectionType); - if (movies.Count > 1) + // Test for multi-editions + if (result.Items.Count > 1 && supportMultiVersion) { - if (supportMultiFileItems) - { - var result = GetMultiFileMovie(movies); + var filenamePrefix = Path.GetFileName(path); - if (result != null) - { - return result; - } - } - if (supportsMultipleSources) + if (!string.IsNullOrWhiteSpace(filenamePrefix)) { - var result = GetMovieWithMultipleSources(movies); - - if (result != null) + if (result.Items.All(i => _fileSystem.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase))) { - return result; + var movie = (T)result.Items[0]; + movie.Name = filenamePrefix; + movie.LocalAlternateVersions = result.Items.Skip(1).Select(i => i.Path).ToList(); + movie.IsInMixedFolder = false; + + _logger.Debug("Multi-version video found: " + movie.Path); + + return movie; } } - return null; } - if (movies.Count == 1) + if (result.Items.Count == 1) { - return movies[0]; + var movie = (T)result.Items[0]; + movie.IsInMixedFolder = false; + return movie; } - if (multiDiscFolders.Count > 0) + if (result.Items.Count == 0 && multiDiscFolders.Count > 0) { return GetMultiDiscMovie<T>(multiDiscFolders, directoryService); } @@ -290,7 +378,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies var folderPaths = multiDiscFolders.Select(i => i.FullName).Where(i => { - var subfolders = directoryService.GetDirectories(i) + var subFileEntries = directoryService.GetFileSystemEntries(i) + .ToList(); + + var subfolders = subFileEntries + .Where(e => (e.Attributes & FileAttributes.Directory) == FileAttributes.Directory) .Select(d => d.Name) .ToList(); @@ -305,6 +397,16 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return true; } + var subFiles = subFileEntries + .Where(e => (e.Attributes & FileAttributes.Directory) != FileAttributes.Directory) + .Select(d => d.Name); + + if (subFiles.Any(IsDvdFile)) + { + videoTypes.Add(VideoType.Dvd); + return true; + } + return false; }).OrderBy(i => i).ToList(); @@ -328,12 +430,12 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { return null; } - + return new T { Path = folderPaths[0], - IsMultiPart = true, + AdditionalParts = folderPaths.Skip(1).ToList(), VideoType = videoTypes[0], @@ -341,85 +443,42 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies }; } - /// <summary> - /// Gets the multi file movie. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="movies">The movies.</param> - /// <returns>``0.</returns> - private T GetMultiFileMovie<T>(IEnumerable<T> movies) - where T : Video, new() + private bool IsInvalid(Folder parent, string collectionType, IEnumerable<FileSystemInfo> files) { - var sortedMovies = movies.OrderBy(i => i.Path).ToList(); - - var firstMovie = sortedMovies[0]; - - var paths = sortedMovies.Select(i => i.Path).ToList(); - - var resolver = new StackResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); - - var result = resolver.ResolveFiles(paths); - - if (result.Stacks.Count != 1) - { - return null; - } - - firstMovie.IsMultiPart = true; - firstMovie.Name = result.Stacks[0].Name; - - // They must all be part of the sequence if we're going to consider it a multi-part movie - return firstMovie; - } - - private T GetMovieWithMultipleSources<T>(IEnumerable<T> movies) - where T : Video, new() - { - var sortedMovies = movies.OrderBy(i => i.Path).ToList(); - - // Cap this at five to help avoid incorrect matching - if (sortedMovies.Count > 5) + if (parent != null) { - return null; + if (parent.IsRoot) + { + return true; + } } - var firstMovie = sortedMovies[0]; - - var filenamePrefix = Path.GetFileName(Path.GetDirectoryName(firstMovie.Path)); - - if (!string.IsNullOrWhiteSpace(filenamePrefix)) + // Don't do any resolving within a series structure + if (string.IsNullOrEmpty(collectionType)) { - if (sortedMovies.All(i => _fileSystem.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase))) + if (parent is Season || parent is Series) { - firstMovie.HasLocalAlternateVersions = true; - - _logger.Debug("Multi-version video found: " + firstMovie.Path); + return true; + } - return firstMovie; + // Since the looping is expensive, this is an optimization to help us avoid it + if (files.Select(i => i.Name).Contains("series.xml", StringComparer.OrdinalIgnoreCase)) + { + return true; } } - return null; - } - - /// <summary> - /// Determines whether [is DVD directory] [the specified directory name]. - /// </summary> - /// <param name="directoryName">Name of the directory.</param> - /// <returns><c>true</c> if [is DVD directory] [the specified directory name]; otherwise, <c>false</c>.</returns> - private bool IsDvdDirectory(string directoryName) - { - return string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase); - } + var validCollectionTypes = new[] + { + string.Empty, + CollectionType.Movies, + CollectionType.HomeVideos, + CollectionType.MusicVideos, + CollectionType.BoxSets, + CollectionType.Movies + }; - /// <summary> - /// Determines whether [is blu ray directory] [the specified directory name]. - /// </summary> - /// <param name="directoryName">Name of the directory.</param> - /// <returns><c>true</c> if [is blu ray directory] [the specified directory name]; otherwise, <c>false</c>.</returns> - private bool IsBluRayDirectory(string directoryName) - { - return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase); + return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase); } } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs index e3fe37be8..5580b442c 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs @@ -17,7 +17,9 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers protected override Photo Resolve(ItemResolveArgs args) { // Must be an image file within a photo collection - if (!args.IsDirectory && IsImageFile(args.Path) && string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase)) + if (!args.IsDirectory && + string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase) && + IsImageFile(args.Path)) { return new Photo { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/PlaylistResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/PlaylistResolver.cs index 7eff53ce1..a95739f22 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/PlaylistResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/PlaylistResolver.cs @@ -28,7 +28,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers if (filename.IndexOf("[playlist]", StringComparison.OrdinalIgnoreCase) != -1) { - return new Playlist { Path = args.Path }; + return new Playlist + { + Path = args.Path, + Name = ResolverHelper.StripBrackets(Path.GetFileName(args.Path)) + }; } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index 839b14a9e..057425ca9 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -1,7 +1,5 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Resolvers; -using MediaBrowser.Model.Entities; using System.Linq; namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV @@ -41,39 +39,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something if (season != null || parent is Series || parent.Parents.OfType<Series>().Any()) { - Episode episode = null; - - if (args.IsDirectory) - { - if (args.ContainsFileSystemEntryByName("video_ts")) - { - episode = new Episode - { - Path = args.Path, - VideoType = VideoType.Dvd - }; - } - if (args.ContainsFileSystemEntryByName("bdmv")) - { - episode = new Episode - { - Path = args.Path, - VideoType = VideoType.BluRay - }; - } - } - - if (episode == null) - { - episode = base.Resolve(args); - } + var episode = ResolveVideo<Episode>(args, false); if (episode != null) { - // The base video resolver is going to fill these in, so null them out - episode.ProductionYear = null; - episode.Name = null; - if (season != null) { episode.ParentIndexNumber = season.IndexNumber; diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs index 30eaf3198..ce7491524 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.IO; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.TV; @@ -81,7 +80,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV if (IsSeriesFolder(args.Path, isTvShowsFolder, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager)) { - return new Series(); + return new Series + { + Path = args.Path, + Name = Path.GetFileName(args.Path) + }; } } @@ -96,12 +99,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV /// <param name="fileSystemChildren">The file system children.</param> /// <param name="directoryService">The directory service.</param> /// <param name="fileSystem">The file system.</param> + /// <param name="logger">The logger.</param> + /// <param name="libraryManager">The library manager.</param> /// <returns><c>true</c> if [is series folder] [the specified path]; otherwise, <c>false</c>.</returns> public static bool IsSeriesFolder(string path, bool considerSeasonlessEntries, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService, IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager) { - // A folder with more than 3 non-season folders in will not becounted as a series - var nonSeriesFolders = 0; - foreach (var child in fileSystemChildren) { var attributes = child.Attributes; @@ -126,19 +128,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV //logger.Debug("{0} is a series because of season folder {1}.", path, child.FullName); return true; } - - if (IsBadFolder(child.Name)) - { - logger.Debug("Invalid folder under series: {0}", child.FullName); - - nonSeriesFolders++; - } - - if (nonSeriesFolders >= 3) - { - logger.Debug("{0} not a series due to 3 or more invalid folders.", path); - return false; - } } else { @@ -176,24 +165,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV return string.Equals(extension, ".disc", StringComparison.OrdinalIgnoreCase); } - private static bool IsBadFolder(string name) - { - if (string.Equals(name, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) - { - return false; - } - if (string.Equals(name, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) - { - return false; - } - if (string.Equals(name, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase)) - { - return false; - } - - return !EntityResolutionHelper.IgnoreFolders.Contains(name, StringComparer.OrdinalIgnoreCase); - } - /// <summary> /// Determines whether [is season folder] [the specified path]. /// </summary> diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs index cde75aea2..97682db66 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs @@ -1,9 +1,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Resolvers; -using MediaBrowser.Model.Entities; -using System; -using System.Linq; namespace MediaBrowser.Server.Implementations.Library.Resolvers { @@ -21,17 +18,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers { if (args.Parent != null) { - var collectionType = args.GetCollectionType() ?? string.Empty; - var accepted = new[] - { - string.Empty, - CollectionType.HomeVideos - }; - - if (!accepted.Contains(collectionType, StringComparer.OrdinalIgnoreCase)) - { - return null; - } + // The movie resolver will handle this + return null; } return base.Resolve(args); @@ -46,6 +34,4 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers get { return ResolverPriority.Last; } } } - - } diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 54c584d47..ed45e890b 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -17,6 +17,7 @@ using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Events; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Querying; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Users; using System; @@ -327,7 +328,10 @@ namespace MediaBrowser.Server.Implementations.Library try { - _dtoServiceFactory().AttachPrimaryImageAspectRatio(dto, user); + _dtoServiceFactory().AttachPrimaryImageAspectRatio(dto, user, new List<ItemFields> + { + ItemFields.PrimaryImageAspectRatio + }); } catch (Exception ex) { @@ -765,5 +769,14 @@ namespace MediaBrowser.Server.Implementations.Library public DateTime ExpirationDate { get; set; } } + public UserPolicy GetUserPolicy(string userId) + { + throw new NotImplementedException(); + } + + public Task UpdateUserPolicy(string userId, UserPolicy userPolicy) + { + throw new NotImplementedException(); + } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsPostScanTask.cs index 575ffec14..60116ac61 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsPostScanTask.cs @@ -32,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - return _libraryManager.ValidateArtists(cancellationToken, progress); + return ((LibraryManager)_libraryManager).ValidateArtists(cancellationToken, progress); } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs index 097e94216..ae6c863a7 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs @@ -32,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - return _libraryManager.ValidateGameGenres(cancellationToken, progress); + return ((LibraryManager)_libraryManager).ValidateGameGenres(cancellationToken, progress); } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GenresPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/GenresPostScanTask.cs index d7add8574..f1d0ef370 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GenresPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GenresPostScanTask.cs @@ -29,7 +29,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - return _libraryManager.ValidateGenres(cancellationToken, progress); + return ((LibraryManager)_libraryManager).ValidateGenres(cancellationToken, progress); } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs index da378228a..280dd90f4 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs @@ -32,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - return _libraryManager.ValidateMusicGenres(cancellationToken, progress); + return ((LibraryManager)_libraryManager).ValidateMusicGenres(cancellationToken, progress); } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/StudiosPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/StudiosPostScanTask.cs index a3a8b8678..0f998b070 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/StudiosPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/StudiosPostScanTask.cs @@ -32,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - return _libraryManager.ValidateStudios(cancellationToken, progress); + return ((LibraryManager)_libraryManager).ValidateStudios(cancellationToken, progress); } } } |
