From 9a820efde33b7a4cfe1dd3e5c37a2f1beaaec896 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 27 May 2013 12:53:10 -0400 Subject: fixes #280 - MB3 Local metadata fetcher for Music not seeing/using Artist Folder.jpg --- .../Library/LibraryManager.cs | 111 +++++++++++++++++++-- 1 file changed, 102 insertions(+), 9 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs') diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index c82ebad51..cf5d75bb7 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -32,6 +32,15 @@ namespace MediaBrowser.Server.Implementations.Library /// public class LibraryManager : ILibraryManager { + /// + /// Gets or sets the postscan tasks. + /// + /// The postscan tasks. + private IEnumerable PostscanTasks { get; set; } + /// + /// Gets or sets the prescan tasks. + /// + /// The prescan tasks. private IEnumerable PrescanTasks { get; set; } /// @@ -100,6 +109,9 @@ namespace MediaBrowser.Server.Implementations.Library /// private readonly IUserManager _userManager; + /// + /// The _user data repository + /// private readonly IUserDataRepository _userDataRepository; /// @@ -113,11 +125,25 @@ namespace MediaBrowser.Server.Implementations.Library /// (typically, multiple user roots). We store them here and be sure they all reference a /// single instance. /// + /// The by reference items. private ConcurrentDictionary ByReferenceItems { get; set; } + /// + /// The _library items cache + /// private ConcurrentDictionary _libraryItemsCache; + /// + /// The _library items cache sync lock + /// private object _libraryItemsCacheSyncLock = new object(); + /// + /// The _library items cache initialized + /// private bool _libraryItemsCacheInitialized; + /// + /// Gets the library items cache. + /// + /// The library items cache. private ConcurrentDictionary LibraryItemsCache { get @@ -127,6 +153,9 @@ namespace MediaBrowser.Server.Implementations.Library } } + /// + /// The _user root folders + /// private readonly ConcurrentDictionary _userRootFolders = new ConcurrentDictionary(); @@ -161,12 +190,14 @@ namespace MediaBrowser.Server.Implementations.Library /// The intro providers. /// The item comparers. /// The prescan tasks. + /// The postscan tasks. public void AddParts(IEnumerable rules, IEnumerable pluginFolders, IEnumerable resolvers, IEnumerable introProviders, IEnumerable itemComparers, - IEnumerable prescanTasks) + IEnumerable prescanTasks, + IEnumerable postscanTasks) { EntityResolutionIgnoreRules = rules; PluginFolderCreators = pluginFolders; @@ -174,6 +205,7 @@ namespace MediaBrowser.Server.Implementations.Library IntroProviders = introProviders; Comparers = itemComparers; PrescanTasks = prescanTasks; + PostscanTasks = postscanTasks; } /// @@ -210,11 +242,27 @@ namespace MediaBrowser.Server.Implementations.Library } } + /// + /// The _internet providers enabled + /// private bool _internetProvidersEnabled; + /// + /// The _people image fetching enabled + /// private bool _peopleImageFetchingEnabled; + /// + /// The _items by name path + /// private string _itemsByNamePath; + /// + /// The _season zero display name + /// private string _seasonZeroDisplayName; + /// + /// Records the configuration values. + /// + /// The configuration. private void RecordConfigurationValues(ServerConfiguration configuration) { _seasonZeroDisplayName = ConfigurationManager.Configuration.SeasonZeroDisplayName; @@ -227,7 +275,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Configurations the updated. /// /// The sender. - /// The instance containing the event data. + /// The instance containing the event data. void ConfigurationUpdated(object sender, EventArgs e) { var config = ConfigurationManager.Configuration; @@ -373,7 +421,7 @@ namespace MediaBrowser.Server.Implementations.Library /// /// Ensure supplied item has only one instance throughout /// - /// + /// The item. /// The proper instance to the item public BaseItem GetOrAddByReferenceItem(BaseItem item) { @@ -800,6 +848,12 @@ namespace MediaBrowser.Server.Implementations.Library _logger.Info("People validation complete"); } + /// + /// Validates the artists. + /// + /// The cancellation token. + /// The progress. + /// Task. public async Task ValidateArtists(CancellationToken cancellationToken, IProgress progress) { const int maxTasks = 25; @@ -924,11 +978,10 @@ namespace MediaBrowser.Server.Implementations.Library // Now validate the entire media library await RootFolder.ValidateChildren(innerProgress, cancellationToken, recursive: true).ConfigureAwait(false); - innerProgress = new ActionableProgress(); - - innerProgress.RegisterAction(pct => progress.Report(80 + pct * .2)); - - await ValidateArtists(cancellationToken, innerProgress); + progress.Report(80); + + // Run post-scan tasks + await RunPostScanTasks(progress, cancellationToken).ConfigureAwait(false); progress.Report(100); } @@ -971,7 +1024,47 @@ namespace MediaBrowser.Server.Implementations.Library } })); - // Run prescan tasks + await Task.WhenAll(tasks).ConfigureAwait(false); + } + + /// + /// Runs the post scan tasks. + /// + /// The progress. + /// The cancellation token. + /// Task. + private async Task RunPostScanTasks(IProgress progress, CancellationToken cancellationToken) + { + var postscanTasks = PostscanTasks.ToList(); + var progressDictionary = new Dictionary(); + + var tasks = postscanTasks.Select(i => Task.Run(async () => + { + var innerProgress = new ActionableProgress(); + + innerProgress.RegisterAction(pct => + { + lock (progressDictionary) + { + progressDictionary[i] = pct; + + double percent = progressDictionary.Values.Sum(); + percent /= postscanTasks.Count; + + progress.Report(80 + percent * .2); + } + }); + + try + { + await i.Run(innerProgress, cancellationToken); + } + catch (Exception ex) + { + _logger.ErrorException("Error running postscan task", ex); + } + })); + await Task.WhenAll(tasks).ConfigureAwait(false); } -- cgit v1.2.3