From 5278959edef763bdf0b4d72ace75efd151ab5024 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 28 Dec 2014 01:21:39 -0500 Subject: sync fixes --- .../Library/LibraryManager.cs | 10 +- .../Library/Resolvers/Audio/MusicAlbumResolver.cs | 45 ++++---- .../Library/Resolvers/Movies/BoxSetResolver.cs | 17 +++ .../Library/Resolvers/Movies/MovieResolver.cs | 39 +------ .../Library/Resolvers/PhotoResolver.cs | 4 +- .../Library/Resolvers/TV/SeriesResolver.cs | 124 ++------------------- .../Library/UserManager.cs | 7 ++ 7 files changed, 60 insertions(+), 186 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library') diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 66125784c..b4a4c7e9a 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -68,6 +68,7 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The entity resolvers enumerable. private IItemResolver[] EntityResolvers { get; set; } + private IMultiItemResolver[] MultiItemResolvers { get; set; } /// /// Gets or sets the comparers. @@ -196,9 +197,10 @@ namespace MediaBrowser.Server.Implementations.Library EntityResolutionIgnoreRules = rules.ToArray(); PluginFolderCreators = pluginFolders.ToArray(); EntityResolvers = resolvers.OrderBy(i => i.Priority).ToArray(); + MultiItemResolvers = EntityResolvers.OfType().ToArray(); IntroProviders = introProviders.ToArray(); Comparers = itemComparers.ToArray(); - + PostscanTasks = postscanTasks.OrderBy(i => { var hasOrder = i as IHasOrder; @@ -344,7 +346,7 @@ namespace MediaBrowser.Server.Implementations.Library try { - await UpdateItem(season, ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false); + await UpdateItem(season, ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { @@ -658,9 +660,7 @@ namespace MediaBrowser.Server.Implementations.Library if (parent != null) { - var multiItemResolvers = EntityResolvers.OfType(); - - foreach (var resolver in multiItemResolvers) + foreach (var resolver in MultiItemResolvers) { var result = resolver.ResolveMultiple(parent, fileList, collectionType, directoryService); diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index 05ff270fc..0f703cb22 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -121,14 +121,28 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio ILibraryManager libraryManager) { var discSubfolderCount = 0; + var notMultiDisc = false; foreach (var fileSystemInfo in list) { if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { - if (allowSubfolders && IsAlbumSubfolder(fileSystemInfo, directoryService, logger, fileSystem, libraryManager)) + if (allowSubfolders) { - discSubfolderCount++; + var path = fileSystemInfo.FullName; + var isMultiDisc = IsMultiDiscFolder(path); + var hasMusic = ContainsMusic(directoryService.GetFileSystemEntries(path), false, directoryService, logger, fileSystem, libraryManager); + + if (isMultiDisc && hasMusic) + { + logger.Debug("Found multi-disc folder: " + path); + discSubfolderCount++; + } + else if (hasMusic) + { + // If there are folders underneath with music that are not multidisc, then this can't be a multi-disc album + notMultiDisc = true; + } } } @@ -140,34 +154,15 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio } } - return discSubfolderCount > 0; - } - - private static bool IsAlbumSubfolder(FileSystemInfo directory, IDirectoryService directoryService, ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager) - { - var path = directory.FullName; - - if (IsMultiDiscFolder(path)) + if (notMultiDisc) { - logger.Debug("Found multi-disc folder: " + path); - - return ContainsMusic(directoryService.GetFileSystemEntries(path), false, directoryService, logger, fileSystem, libraryManager); + return false; } - return false; - } - - public static bool IsMultiDiscFolder(string path) - { - return IsMultiDiscAlbumFolder(path); + return discSubfolderCount > 0 && discSubfolderCount > 10; } - /// - /// Determines whether [is multi disc album folder] [the specified path]. - /// - /// The path. - /// true if [is multi disc album folder] [the specified path]; otherwise, false. - private static bool IsMultiDiscAlbumFolder(string path) + private static bool IsMultiDiscFolder(string path) { var parser = new AlbumParser(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); var result = parser.ParseMultiPart(path); diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs index e3447afc9..390113cc8 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Model.Entities; using System; using System.IO; +using System.Linq; namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { @@ -24,6 +25,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies // Contains [boxset] in the path if (args.IsDirectory) { + if (IsInvalid(args.GetCollectionType())) + { + return null; + } + var filename = Path.GetFileName(args.Path); if (string.IsNullOrEmpty(filename)) @@ -45,6 +51,17 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return null; } + private bool IsInvalid(string collectionType) + { + var validCollectionTypes = new[] + { + CollectionType.Movies, + CollectionType.BoxSets + }; + + return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase); + } + /// /// Sets the initial item values. /// diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 01dc4db8a..f7a82c5b8 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -2,7 +2,6 @@ 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; @@ -183,7 +182,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return FindMovie public class SeriesResolver : FolderResolver { - private readonly IFileSystem _fileSystem; - private readonly ILogger _logger; - private readonly ILibraryManager _libraryManager; - - public SeriesResolver(IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager) - { - _fileSystem = fileSystem; - _logger = logger; - _libraryManager = libraryManager; - } - /// /// Gets the priority. /// @@ -50,27 +33,16 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV { if (args.IsDirectory) { - // Avoid expensive tests against VF's and all their children by not allowing this - if (args.Parent.IsRoot) - { - return null; - } - var collectionType = args.GetCollectionType(); // If there's a collection type and it's not tv, it can't be a series - if (!string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) - { - return null; - } - - if (args.HasParent() || args.HasParent()) - { - return null; - } - - if (IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager)) + if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { + if (args.HasParent()) + { + return null; + } + return new Series { Path = args.Path, @@ -82,88 +54,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV return null; } - /// - /// Determines whether [is series folder] [the specified path]. - /// - /// The path. - /// The file system children. - /// The directory service. - /// The file system. - /// The logger. - /// The library manager. - /// true if [is series folder] [the specified path]; otherwise, false. - public static bool IsSeriesFolder(string path, IEnumerable fileSystemChildren, IDirectoryService directoryService, IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager) - { - foreach (var child in fileSystemChildren) - { - var attributes = child.Attributes; - - if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) - { - //logger.Debug("Igoring series file or folder marked hidden: {0}", child.FullName); - continue; - } - - // Can't enforce this because files saved by Bitcasa are always marked System - //if ((attributes & FileAttributes.System) == FileAttributes.System) - //{ - // logger.Debug("Igoring series subfolder marked system: {0}", child.FullName); - // continue; - //} - - if ((attributes & FileAttributes.Directory) == FileAttributes.Directory) - { - if (IsSeasonFolder(child.FullName)) - { - //logger.Debug("{0} is a series because of season folder {1}.", path, child.FullName); - return true; - } - } - else - { - var fullName = child.FullName; - - if (libraryManager.IsVideoFile(fullName) || IsVideoPlaceHolder(fullName)) - { - return true; - } - } - } - - logger.Debug("{0} is not a series folder.", path); - return false; - } - - /// - /// Determines whether [is place holder] [the specified path]. - /// - /// The path. - /// true if [is place holder] [the specified path]; otherwise, false. - /// path - private static bool IsVideoPlaceHolder(string path) - { - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentNullException("path"); - } - - var extension = Path.GetExtension(path); - - return string.Equals(extension, ".disc", StringComparison.OrdinalIgnoreCase); - } - - /// - /// Determines whether [is season folder] [the specified path]. - /// - /// The path. - /// true if [is season folder] [the specified path]; otherwise, false. - private static bool IsSeasonFolder(string path) - { - var seasonNumber = new SeasonPathParser(new ExtendedNamingOptions(), new RegexProvider()).Parse(path, true).SeasonNumber; - - return seasonNumber.HasValue; - } - /// /// Sets the initial item values. /// diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 1a45d35a0..503af4970 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -860,6 +860,13 @@ namespace MediaBrowser.Server.Implementations.Library private async Task UpdateUserPolicy(User user, UserPolicy userPolicy, bool fireEvent) { + // The xml serializer will output differently if the type is not exact + if (userPolicy.GetType() != typeof(UserPolicy)) + { + var json = _jsonSerializer.SerializeToString(userPolicy); + userPolicy = _jsonSerializer.DeserializeFromString(json); + } + var updateConfig = user.Policy.IsAdministrator != userPolicy.IsAdministrator || user.Policy.EnableLiveTvManagement != userPolicy.EnableLiveTvManagement || user.Policy.EnableLiveTvAccess != userPolicy.EnableLiveTvAccess || -- cgit v1.2.3