diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library')
13 files changed, 35 insertions, 191 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 813d279ab..735565e25 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -38,24 +38,13 @@ namespace MediaBrowser.Server.Implementations.Library /// Gets or sets the postscan tasks. /// </summary> /// <value>The postscan tasks.</value> - private IEnumerable<ILibraryPostScanTask> PostscanTasks { get; set; } - /// <summary> - /// Gets or sets the prescan tasks. - /// </summary> - /// <value>The prescan tasks.</value> - private IEnumerable<ILibraryPrescanTask> PrescanTasks { get; set; } - - /// <summary> - /// Gets or sets the people prescan tasks. - /// </summary> - /// <value>The people prescan tasks.</value> - private IEnumerable<IPeoplePrescanTask> PeoplePrescanTasks { get; set; } + private ILibraryPostScanTask[] PostscanTasks { get; set; } /// <summary> /// Gets the intro providers. /// </summary> /// <value>The intro providers.</value> - private IEnumerable<IIntroProvider> IntroProviders { get; set; } + private IIntroProvider[] IntroProviders { get; set; } /// <summary> /// Gets the list of entity resolution ignore rules @@ -205,26 +194,27 @@ namespace MediaBrowser.Server.Implementations.Library /// <param name="resolvers">The resolvers.</param> /// <param name="introProviders">The intro providers.</param> /// <param name="itemComparers">The item comparers.</param> - /// <param name="prescanTasks">The prescan tasks.</param> /// <param name="postscanTasks">The postscan tasks.</param> - /// <param name="peoplePrescanTasks">The people prescan tasks.</param> public void AddParts(IEnumerable<IResolverIgnoreRule> rules, IEnumerable<IVirtualFolderCreator> pluginFolders, IEnumerable<IItemResolver> resolvers, IEnumerable<IIntroProvider> introProviders, IEnumerable<IBaseItemComparer> itemComparers, - IEnumerable<ILibraryPrescanTask> prescanTasks, - IEnumerable<ILibraryPostScanTask> postscanTasks, - IEnumerable<IPeoplePrescanTask> peoplePrescanTasks) + IEnumerable<ILibraryPostScanTask> postscanTasks) { EntityResolutionIgnoreRules = rules.ToArray(); PluginFolderCreators = pluginFolders.ToArray(); EntityResolvers = resolvers.OrderBy(i => i.Priority).ToArray(); - IntroProviders = introProviders; + IntroProviders = introProviders.ToArray(); Comparers = itemComparers.ToArray(); - PrescanTasks = prescanTasks; - PostscanTasks = postscanTasks; - PeoplePrescanTasks = peoplePrescanTasks; + + PostscanTasks = postscanTasks.OrderBy(i => + { + var hasOrder = i as IHasOrder; + + return hasOrder == null ? 0 : hasOrder.Order; + + }).ToArray(); } /// <summary> @@ -507,7 +497,9 @@ namespace MediaBrowser.Server.Implementations.Library // 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); + var directoryService = new DirectoryService(_logger); + + var fileSystemDictionary = FileData.GetFilteredFileSystemEntries(directoryService, args.Path, _fileSystem, _logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf); // Need to remove subpaths that may have been resolved from shortcuts // Example: if \\server\movies exists, then strip out \\server\movies\action @@ -845,7 +837,7 @@ namespace MediaBrowser.Server.Implementations.Library /// <returns>Task.</returns> public Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress) { - return new PeopleValidator(this, PeoplePrescanTasks, _logger).ValidatePeople(cancellationToken, progress); + return new PeopleValidator(this, _logger).ValidatePeople(cancellationToken, progress); } /// <summary> @@ -955,7 +947,7 @@ namespace MediaBrowser.Server.Implementations.Library progress.Report(.5); // Start by just validating the children of the root, but go no further - await RootFolder.ValidateChildren(new Progress<double>(), cancellationToken, recursive: false); + await RootFolder.ValidateChildren(new Progress<double>(), cancellationToken, new MetadataRefreshOptions(), recursive: false); progress.Report(1); @@ -970,17 +962,12 @@ namespace MediaBrowser.Server.Implementations.Library innerProgress.RegisterAction(pct => progress.Report(2 + pct * .13)); - // Run prescan tasks - await RunPrescanTasks(innerProgress, cancellationToken).ConfigureAwait(false); - - progress.Report(15); - innerProgress = new ActionableProgress<double>(); - innerProgress.RegisterAction(pct => progress.Report(15 + pct * .6)); + innerProgress.RegisterAction(pct => progress.Report(2 + pct * .73)); // Now validate the entire media library - await RootFolder.ValidateChildren(innerProgress, cancellationToken, recursive: true).ConfigureAwait(false); + await RootFolder.ValidateChildren(innerProgress, cancellationToken, new MetadataRefreshOptions(), recursive: true).ConfigureAwait(false); progress.Report(75); @@ -999,55 +986,6 @@ namespace MediaBrowser.Server.Implementations.Library } /// <summary> - /// Runs the prescan tasks. - /// </summary> - /// <param name="progress">The progress.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - private async Task RunPrescanTasks(IProgress<double> progress, CancellationToken cancellationToken) - { - var tasks = PrescanTasks.ToList(); - - var numComplete = 0; - var numTasks = tasks.Count; - - foreach (var task in tasks) - { - var innerProgress = new ActionableProgress<double>(); - - // Prevent access to modified closure - var currentNumComplete = numComplete; - - innerProgress.RegisterAction(pct => - { - double innerPercent = (currentNumComplete * 100) + pct; - innerPercent /= numTasks; - progress.Report(innerPercent); - }); - - try - { - await task.Run(innerProgress, cancellationToken); - } - catch (OperationCanceledException) - { - _logger.Info("Pre-scan task cancelled: {0}", task.GetType().Name); - } - catch (Exception ex) - { - _logger.ErrorException("Error running pre-scan task", ex); - } - - numComplete++; - double percent = numComplete; - percent /= numTasks; - progress.Report(percent * 100); - } - - progress.Report(100); - } - - /// <summary> /// Runs the post scan tasks. /// </summary> /// <param name="progress">The progress.</param> @@ -1109,8 +1047,7 @@ namespace MediaBrowser.Server.Implementations.Library cancellationToken.ThrowIfCancellationRequested(); - await userRootFolder.ValidateChildren(new Progress<double>(), cancellationToken, recursive: false).ConfigureAwait(false); - var b = true; + await userRootFolder.ValidateChildren(new Progress<double>(), cancellationToken, new MetadataRefreshOptions(), recursive: false).ConfigureAwait(false); } /// <summary> @@ -1464,22 +1401,7 @@ namespace MediaBrowser.Server.Implementations.Library .Distinct() .SelectMany(i => i.Children) .OfType<CollectionFolder>() - .Where(i => - { - var locationType = i.LocationType; - - if (locationType == LocationType.Remote || locationType == LocationType.Virtual) - { - return false; - } - - if (string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return i.PhysicalLocations.Contains(item.Path); - }) + .Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path)) .Select(i => i.CollectionType) .Where(i => !string.IsNullOrEmpty(i)) .Distinct() diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 998895cbf..f355f4bf6 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Resolvers; diff --git a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs index 40ef5304c..1d9eea866 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs @@ -79,7 +79,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators { cancellationToken.ThrowIfCancellationRequested(); - // Only do this for artists accessed by name. Folder-based artists use ArtistInfoFromSongsProvider + // Only do this for artists accessed by name. Folder-based artists get it from the normal refresh if (artist.IsAccessedByName && !artist.LockedFields.Contains(MetadataFields.Genres)) { // Avoid implicitly captured closure @@ -91,9 +91,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators .ToList(); } - // Populate counts of items - //SetItemCounts(artist, null, allItems.OfType<IHasArtist>()); - foreach (var lib in userLibraries) { SetItemCounts(artist, lib.Item1, lib.Item2); diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs index 9e140c626..097e94216 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs @@ -16,10 +16,9 @@ namespace MediaBrowser.Server.Implementations.Library.Validators private readonly ILibraryManager _libraryManager; /// <summary> - /// Initializes a new instance of the <see cref="GameGenresPostScanTask"/> class. + /// Initializes a new instance of the <see cref="GameGenresPostScanTask" /> class. /// </summary> /// <param name="libraryManager">The library manager.</param> - /// <param name="userManager">The user manager.</param> public GameGenresPostScanTask(ILibraryManager libraryManager) { _libraryManager = libraryManager; diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs index c7af7a238..9e64c7810 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs @@ -47,9 +47,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - // Populate counts of items - //SetItemCounts(null, allLibraryItems, masterDictionary); - progress.Report(2); var numComplete = 0; @@ -98,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) + private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) { var itemByName = _libraryManager.GetGameGenre(name); @@ -109,7 +106,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators itemByName.SetItemByNameCounts(libraryId, itemCounts); } - await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); + return itemByName.RefreshMetadata(cancellationToken); } private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs index cb1253df0..e0a9e2ce8 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs @@ -48,9 +48,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - // Populate counts of items - //SetItemCounts(null, allLibraryItems, masterDictionary); - progress.Report(2); var numComplete = 0; @@ -99,7 +96,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) + private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) { var itemByName = _libraryManager.GetGenre(name); @@ -110,7 +107,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators itemByName.SetItemByNameCounts(libraryId, itemCounts); } - await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); + return itemByName.RefreshMetadata(cancellationToken); } private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) diff --git a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs index e5535c6e0..da378228a 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs @@ -19,7 +19,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// Initializes a new instance of the <see cref="ArtistsPostScanTask" /> class. /// </summary> /// <param name="libraryManager">The library manager.</param> - /// <param name="userManager">The user manager.</param> public MusicGenresPostScanTask(ILibraryManager libraryManager) { _libraryManager = libraryManager; diff --git a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs index 57a6a612b..b55ab1cbe 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs @@ -48,9 +48,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - // Populate counts of items - //SetItemCounts(null, allLibraryItems, masterDictionary); - progress.Report(2); var numComplete = 0; @@ -99,7 +96,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) + private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) { var itemByName = _libraryManager.GetMusicGenre(name); @@ -110,7 +107,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators itemByName.SetItemByNameCounts(libraryId, itemCounts); } - await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); + return itemByName.RefreshMetadata(cancellationToken); } private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) diff --git a/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs index 706ff67a7..86c5dbc4c 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs @@ -53,9 +53,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - // Populate counts of items - //SetItemCounts(null, allLibraryItems, masterDictionary); - progress.Report(2); var numComplete = 0; diff --git a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs index 26e9a23e9..268bccd7a 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs @@ -3,7 +3,6 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using MoreLinq; using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -24,19 +23,15 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// </summary> private readonly ILogger _logger; - private readonly IEnumerable<IPeoplePrescanTask> _prescanTasks; - /// <summary> /// Initializes a new instance of the <see cref="PeopleValidator" /> class. /// </summary> /// <param name="libraryManager">The library manager.</param> - /// <param name="prescanTasks">The prescan tasks.</param> /// <param name="logger">The logger.</param> - public PeopleValidator(ILibraryManager libraryManager, IEnumerable<IPeoplePrescanTask> prescanTasks, ILogger logger) + public PeopleValidator(ILibraryManager libraryManager, ILogger logger) { _libraryManager = libraryManager; _logger = logger; - _prescanTasks = prescanTasks; } /// <summary> @@ -51,11 +46,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators innerProgress.RegisterAction(pct => progress.Report(pct * .15)); - // Run prescan tasks - await RunPrescanTasks(innerProgress, cancellationToken).ConfigureAwait(false); - - progress.Report(15); - var people = _libraryManager.RootFolder.GetRecursiveChildren() .SelectMany(c => c.People) .DistinctBy(p => p.Name, StringComparer.OrdinalIgnoreCase) @@ -94,55 +84,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators GC.Collect(2, GCCollectionMode.Forced, true); GC.Collect(2, GCCollectionMode.Forced, true); } - - /// <summary> - /// Runs the prescan tasks. - /// </summary> - /// <param name="progress">The progress.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - private async Task RunPrescanTasks(IProgress<double> progress, CancellationToken cancellationToken) - { - var tasks = _prescanTasks.ToList(); - - var numComplete = 0; - var numTasks = tasks.Count; - - foreach (var task in tasks) - { - var innerProgress = new ActionableProgress<double>(); - - // Prevent access to modified closure - var currentNumComplete = numComplete; - - innerProgress.RegisterAction(pct => - { - double innerPercent = (currentNumComplete * 100) + pct; - innerPercent /= numTasks; - progress.Report(innerPercent); - }); - - try - { - await task.Run(innerProgress, cancellationToken); - } - catch (OperationCanceledException) - { - _logger.Info("Pre-scan task cancelled: {0}", task.GetType().Name); - break; - } - catch (Exception ex) - { - _logger.ErrorException("Error running pre-scan task", ex); - } - - numComplete++; - double percent = numComplete; - percent /= numTasks; - progress.Report(percent * 100); - } - - progress.Report(100); - } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/StudiosPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/StudiosPostScanTask.cs index fb9562da2..a3a8b8678 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/StudiosPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/StudiosPostScanTask.cs @@ -19,7 +19,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// Initializes a new instance of the <see cref="ArtistsPostScanTask" /> class. /// </summary> /// <param name="libraryManager">The library manager.</param> - /// <param name="userManager">The user manager.</param> public StudiosPostScanTask(ILibraryManager libraryManager) { _libraryManager = libraryManager; diff --git a/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs index 0f4ff562e..54fadfb77 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs @@ -47,9 +47,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - // Populate counts of items - //SetItemCounts(null, allLibraryItems, masterDictionary); - progress.Report(2); var numComplete = 0; @@ -98,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - private async Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) + private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) { var itemByName = _libraryManager.GetStudio(name); @@ -109,7 +106,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators itemByName.SetItemByNameCounts(libraryId, itemCounts); } - await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); + return itemByName.RefreshMetadata(cancellationToken); } private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) diff --git a/MediaBrowser.Server.Implementations/Library/Validators/YearsPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/YearsPostScanTask.cs index c65568db9..78783db90 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/YearsPostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/YearsPostScanTask.cs @@ -26,6 +26,8 @@ namespace MediaBrowser.Server.Implementations.Library.Validators .Distinct() .ToList(); + progress.Report(10); + var count = allYears.Count; var numComplete = 0; |
