diff options
| author | Tim Hobbs <jesus.tesh@gmail.com> | 2014-03-13 06:26:20 -0700 |
|---|---|---|
| committer | Tim Hobbs <jesus.tesh@gmail.com> | 2014-03-13 06:26:20 -0700 |
| commit | 9e33966ee120134d89f7aa21204b7ffc814dd29a (patch) | |
| tree | 297982b6cd4269ada15d93cec859b7cba27c0c1a /MediaBrowser.Server.Implementations/Library | |
| parent | dd4a1ff4b50f58c27af223202454f80d45de4af1 (diff) | |
| parent | b7bcc2450694105de9f9fc8cc07d2cfc4d9d7c96 (diff) | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library')
12 files changed, 86 insertions, 401 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 6e9d803bf..0b1947d4c 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -5,6 +5,7 @@ using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; @@ -484,6 +485,9 @@ namespace MediaBrowser.Server.Implementations.Library await ItemRepository.DeleteItem(child.Id, CancellationToken.None).ConfigureAwait(false); } + BaseItem removed; + _libraryItemsCache.TryRemove(item.Id, out removed); + ReportItemRemoved(item); } @@ -922,10 +926,10 @@ namespace MediaBrowser.Server.Implementations.Library /// <returns>Task.</returns> public Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress) { - // Ensure the location is unavailable. + // Ensure the location is available. Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.PeoplePath); - return new PeopleValidator(this, _logger).ValidatePeople(cancellationToken, progress); + return new PeopleValidator(this, _logger).ValidatePeople(cancellationToken, new MetadataRefreshOptions(), progress); } /// <summary> @@ -953,7 +957,7 @@ namespace MediaBrowser.Server.Implementations.Library // Ensure the location is unavailable. Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.MusicGenrePath); - return new MusicGenresValidator(this, _userManager, _logger).Run(progress, cancellationToken); + return new MusicGenresValidator(this, _logger).Run(progress, cancellationToken); } /// <summary> diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index 871171541..ac1927931 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -48,7 +48,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio var collectionType = args.GetCollectionType(); - // If there's a collection type and it's not music, it can't be a series + // If there's a collection type and it's not music, don't allow it. if (!string.IsNullOrEmpty(collectionType) && !string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase)) { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index ac9b42efb..16c0d1a27 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -56,21 +56,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { return null; } - - // If the parent is not a boxset, the only other allowed parent type is Folder - if (!(args.Parent is BoxSet)) - { - if (args.Parent.GetType() != typeof(Folder)) - { - return null; - } - } - } - - // Since the looping is expensive, this is an optimization to help us avoid it - if (args.Path.IndexOf("[tvdbid", StringComparison.OrdinalIgnoreCase) != -1) - { - return null; } var isDirectory = args.IsDirectory; @@ -89,34 +74,31 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies // Find movies with their own folders if (isDirectory) { - if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1 || - string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<Trailer>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService); + return FindMovie<Trailer>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, false); } - if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1 || - string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService); + return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, false); } - if (args.Path.IndexOf("[adultvideos]", StringComparison.OrdinalIgnoreCase) != -1 || - string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<AdultVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService); + return FindMovie<AdultVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true); } if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService); + return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true); } if (string.IsNullOrEmpty(collectionType) || string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService); + return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true); } return null; @@ -202,8 +184,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies /// <param name="path">The path.</param> /// <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> /// <returns>Movie.</returns> - private T FindMovie<T>(string path, Folder parent, IEnumerable<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService) + private T FindMovie<T>(string path, Folder parent, IEnumerable<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, bool supportMultiFileItems) where T : Video, new() { var movies = new List<T>(); @@ -264,7 +248,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies } } - if (movies.Count > 1) + if (movies.Count > 1 && supportMultiFileItems) { return GetMultiFileMovie(movies); } diff --git a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs index 12686f542..aaafd35a9 100644 --- a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs +++ b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs @@ -37,6 +37,12 @@ namespace MediaBrowser.Server.Implementations.Library var results = await GetSearchHints(inputItems, query).ConfigureAwait(false); + // Include item types + if (query.IncludeItemTypes.Length > 0) + { + results = results.Where(f => query.IncludeItemTypes.Contains(f.Item.GetType().Name, StringComparer.OrdinalIgnoreCase)); + } + var searchResultArray = results.ToArray(); results = searchResultArray; @@ -96,7 +102,9 @@ namespace MediaBrowser.Server.Implementations.Library if (query.IncludeArtists) { // Find artists - var artists = _libraryManager.GetAllArtists(items) + var artists = items.OfType<Audio>() + .SelectMany(i => i.AllArtists) + .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); foreach (var item in artists) diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 8654a26ce..06028d37e 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -189,15 +189,10 @@ namespace MediaBrowser.Server.Implementations.Library /// Refreshes metadata for each user /// </summary> /// <param name="cancellationToken">The cancellation token.</param> - /// <param name="force">if set to <c>true</c> [force].</param> /// <returns>Task.</returns> - public Task RefreshUsersMetadata(CancellationToken cancellationToken, bool force = false) + public Task RefreshUsersMetadata(CancellationToken cancellationToken) { - var tasks = Users.Select(user => user.RefreshMetadata(new MetadataRefreshOptions - { - ReplaceAllMetadata = force - - }, cancellationToken)).ToList(); + var tasks = Users.Select(user => user.RefreshMetadata(new MetadataRefreshOptions(), cancellationToken)).ToList(); return Task.WhenAll(tasks); } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs index 1d9eea866..5968d847e 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs @@ -1,8 +1,6 @@ using MediaBrowser.Common.Progress; -using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using System; @@ -69,10 +67,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var numComplete = 0; - var userLibraries = _userManager.Users - .Select(i => new Tuple<Guid, List<IHasArtist>>(i.Id, i.RootFolder.GetRecursiveChildren(i).OfType<IHasArtist>().ToList())) - .ToList(); - var numArtists = allArtists.Count; foreach (var artist in allArtists) @@ -91,11 +85,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators .ToList(); } - foreach (var lib in userLibraries) - { - SetItemCounts(artist, lib.Item1, lib.Item2); - } - numComplete++; double percent = numComplete; percent /= numArtists; @@ -108,37 +97,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } /// <summary> - /// Sets the item counts. - /// </summary> - /// <param name="artist">The artist.</param> - /// <param name="userId">The user id.</param> - /// <param name="allItems">All items.</param> - private void SetItemCounts(MusicArtist artist, Guid? userId, IEnumerable<IHasArtist> allItems) - { - var name = artist.Name; - - var items = allItems - .Where(i => i.HasArtist(name)) - .ToList(); - - var counts = new ItemByNameCounts - { - TotalCount = items.Count, - - SongCount = items.OfType<Audio>().Count(), - - AlbumCount = items.OfType<MusicAlbum>().Count(), - - MusicVideoCount = items.OfType<MusicVideo>().Count() - }; - - if (userId.HasValue) - { - artist.SetItemByNameCounts(userId.Value, counts); - } - } - - /// <summary> /// Gets all artists. /// </summary> /// <param name="allSongs">All songs.</param> @@ -147,7 +105,8 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task{Artist[]}.</returns> private async Task<List<MusicArtist>> GetAllArtists(IEnumerable<Audio> allSongs, CancellationToken cancellationToken, IProgress<double> progress) { - var allArtists = _libraryManager.GetAllArtists(allSongs) + var allArtists = allSongs.SelectMany(i => i.AllArtists) + .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); var returnArtists = new List<MusicArtist>(allArtists.Count); diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs index 9e64c7810..6b658e175 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs @@ -2,7 +2,6 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -41,38 +40,24 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public async Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - var userLibraries = _userManager.Users - .Select(i => new Tuple<Guid, List<Game>>(i.Id, i.RootFolder.GetRecursiveChildren(i).OfType<Game>().ToList())) + var items = _libraryManager.RootFolder.RecursiveChildren.Where(i => (i is Game)) + .SelectMany(i => i.Genres) + .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - progress.Report(2); - var numComplete = 0; + var count = items.Count; - foreach (var lib in userLibraries) + foreach (var name in items) { - SetItemCounts(lib.Item1, lib.Item2, masterDictionary); - - numComplete++; - double percent = numComplete; - percent /= userLibraries.Count; - percent *= 8; - - progress.Report(percent); - } + cancellationToken.ThrowIfCancellationRequested(); - progress.Report(10); - - var count = masterDictionary.Count; - numComplete = 0; - - foreach (var name in masterDictionary.Keys) - { try { - await UpdateItemByNameCounts(name, cancellationToken, masterDictionary[name]).ConfigureAwait(false); + var itemByName = _libraryManager.GetGameGenre(name); + + await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -81,7 +66,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } catch (Exception ex) { - _logger.ErrorException("Error updating counts for {0}", ex, name); + _logger.ErrorException("Error refreshing {0}", ex, name); } numComplete++; @@ -94,32 +79,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - - private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) - { - var itemByName = _libraryManager.GetGameGenre(name); - - foreach (var libraryId in counts.Keys) - { - var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - - itemByName.SetItemByNameCounts(libraryId, itemCounts); - } - - return itemByName.RefreshMetadata(cancellationToken); - } - - private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) - { - foreach (var media in allItems) - { - var names = media - .Genres - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToList(); - - CountHelpers.SetItemCounts(userId, media, names, masterDictionary); - } - } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs index e0a9e2ce8..b0dee9aaf 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs @@ -3,7 +3,6 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -42,38 +41,24 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public async Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - var userLibraries = _userManager.Users - .Select(i => new Tuple<Guid, IList<BaseItem>>(i.Id, i.RootFolder.GetRecursiveChildren(i, m => !(m is IHasMusicGenres) && !(m is Game)))) + var items = _libraryManager.RootFolder.RecursiveChildren.Where(i => !(i is IHasMusicGenres) && !(i is Game)) + .SelectMany(i => i.Genres) + .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - progress.Report(2); - var numComplete = 0; + var count = items.Count; - foreach (var lib in userLibraries) + foreach (var name in items) { - SetItemCounts(lib.Item1, lib.Item2, masterDictionary); - - numComplete++; - double percent = numComplete; - percent /= userLibraries.Count; - percent *= 8; - - progress.Report(percent); - } + cancellationToken.ThrowIfCancellationRequested(); - progress.Report(10); - - var count = masterDictionary.Count; - numComplete = 0; - - foreach (var name in masterDictionary.Keys) - { try { - await UpdateItemByNameCounts(name, cancellationToken, masterDictionary[name]).ConfigureAwait(false); + var itemByName = _libraryManager.GetGenre(name); + + await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -82,7 +67,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } catch (Exception ex) { - _logger.ErrorException("Error updating counts for {0}", ex, name); + _logger.ErrorException("Error refreshing {0}", ex, name); } numComplete++; @@ -95,32 +80,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - - private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) - { - var itemByName = _libraryManager.GetGenre(name); - - foreach (var libraryId in counts.Keys) - { - var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - - itemByName.SetItemByNameCounts(libraryId, itemCounts); - } - - return itemByName.RefreshMetadata(cancellationToken); - } - - private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) - { - foreach (var media in allItems) - { - var names = media - .Genres - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToList(); - - CountHelpers.SetItemCounts(userId, media, names, masterDictionary); - } - } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs index b55ab1cbe..aa6c6281e 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs @@ -1,9 +1,7 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -18,19 +16,13 @@ namespace MediaBrowser.Server.Implementations.Library.Validators private readonly ILibraryManager _libraryManager; /// <summary> - /// The _user manager - /// </summary> - private readonly IUserManager _userManager; - - /// <summary> /// The _logger /// </summary> private readonly ILogger _logger; - public MusicGenresValidator(ILibraryManager libraryManager, IUserManager userManager, ILogger logger) + public MusicGenresValidator(ILibraryManager libraryManager, ILogger logger) { _libraryManager = libraryManager; - _userManager = userManager; _logger = logger; } @@ -42,38 +34,24 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public async Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - var userLibraries = _userManager.Users - .Select(i => new Tuple<Guid, IList<BaseItem>>(i.Id, i.RootFolder.GetRecursiveChildren(i, m => m is IHasMusicGenres))) + var items = _libraryManager.RootFolder.RecursiveChildren.Where(i => (i is IHasMusicGenres)) + .SelectMany(i => i.Genres) + .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - progress.Report(2); - var numComplete = 0; + var count = items.Count; - foreach (var lib in userLibraries) + foreach (var name in items) { - SetItemCounts(lib.Item1, lib.Item2, masterDictionary); - - numComplete++; - double percent = numComplete; - percent /= userLibraries.Count; - percent *= 8; - - progress.Report(percent); - } - - progress.Report(10); + cancellationToken.ThrowIfCancellationRequested(); - var count = masterDictionary.Count; - numComplete = 0; - - foreach (var name in masterDictionary.Keys) - { try { - await UpdateItemByNameCounts(name, cancellationToken, masterDictionary[name]).ConfigureAwait(false); + var itemByName = _libraryManager.GetMusicGenre(name); + + await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -82,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } catch (Exception ex) { - _logger.ErrorException("Error updating counts for {0}", ex, name); + _logger.ErrorException("Error refreshing {0}", ex, name); } numComplete++; @@ -95,32 +73,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - - private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) - { - var itemByName = _libraryManager.GetMusicGenre(name); - - foreach (var libraryId in counts.Keys) - { - var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - - itemByName.SetItemByNameCounts(libraryId, itemCounts); - } - - return itemByName.RefreshMetadata(cancellationToken); - } - - private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) - { - foreach (var media in allItems) - { - var names = media - .Genres - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToList(); - - CountHelpers.SetItemCounts(userId, media, names, masterDictionary); - } - } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs index 86c5dbc4c..d11e62a1a 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs @@ -1,10 +1,7 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Logging; using System; -using System.Collections.Generic; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -18,19 +15,13 @@ namespace MediaBrowser.Server.Implementations.Library.Validators private readonly ILibraryManager _libraryManager; /// <summary> - /// The _user manager - /// </summary> - private readonly IUserManager _userManager; - - /// <summary> /// The _logger /// </summary> private readonly ILogger _logger; - public PeoplePostScanTask(ILibraryManager libraryManager, IUserManager userManager, ILogger logger) + public PeoplePostScanTask(ILibraryManager libraryManager, ILogger logger) { _libraryManager = libraryManager; - _userManager = userManager; _logger = logger; } @@ -42,94 +33,12 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - return RunInternal(progress, cancellationToken); - } - - private async Task RunInternal(IProgress<double> progress, CancellationToken cancellationToken) - { - var userLibraries = _userManager.Users - .Select(i => new Tuple<Guid, IList<BaseItem>>(i.Id, i.RootFolder.GetRecursiveChildren(i, null))) - .ToList(); - - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - - progress.Report(2); - - var numComplete = 0; - - foreach (var lib in userLibraries) + return new PeopleValidator(_libraryManager, _logger).ValidatePeople(cancellationToken, new MetadataRefreshOptions { - cancellationToken.ThrowIfCancellationRequested(); - - SetItemCounts(lib.Item1, lib.Item2, masterDictionary); - - numComplete++; - double percent = numComplete; - percent /= userLibraries.Count; - percent *= 8; + ImageRefreshMode = ImageRefreshMode.ValidationOnly, + MetadataRefreshMode = MetadataRefreshMode.None - progress.Report(percent); - } - - progress.Report(10); - - var count = masterDictionary.Count; - numComplete = 0; - - foreach (var name in masterDictionary.Keys) - { - cancellationToken.ThrowIfCancellationRequested(); - - try - { - var counts = masterDictionary[name]; - - var itemByName = _libraryManager.GetPerson(name); - - // The only purpose here is to be able to react to image changes without running the people task. - // All other metadata can wait for that. - await itemByName.RefreshMetadata(new MetadataRefreshOptions - { - ImageRefreshMode = ImageRefreshMode.ValidationOnly, - MetadataRefreshMode = MetadataRefreshMode.None - - }, cancellationToken).ConfigureAwait(false); - - foreach (var libraryId in counts.Keys) - { - var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - - itemByName.SetItemByNameCounts(libraryId, itemCounts); - } - } - catch (Exception ex) - { - _logger.ErrorException("Error updating counts for {0}", ex, name); - } - - numComplete++; - double percent = numComplete; - percent /= count; - percent *= 90; - - progress.Report(percent + 10); - } - - progress.Report(100); + }, progress); } - - private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) - { - foreach (var media in allItems) - { - var names = media - .People.Select(i => i.Name) - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToList(); - - CountHelpers.SetItemCounts(userId, media, names, masterDictionary); - } - } - } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs index 268bccd7a..722c24a10 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Progress; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Logging; using MoreLinq; using System; @@ -38,9 +39,10 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// Validates the people. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> + /// <param name="options">The options.</param> /// <param name="progress">The progress.</param> /// <returns>Task.</returns> - public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress) + public async Task ValidatePeople(CancellationToken cancellationToken, MetadataRefreshOptions options, IProgress<double> progress) { var innerProgress = new ActionableProgress<double>(); @@ -61,7 +63,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators { var item = _libraryManager.GetPerson(person.Name); - await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); + await item.RefreshMetadata(options, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { diff --git a/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs index 54fadfb77..a2ec9788c 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs @@ -1,8 +1,6 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -41,38 +39,24 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// <returns>Task.</returns> public async Task Run(IProgress<double> progress, CancellationToken cancellationToken) { - var userLibraries = _userManager.Users - .Select(i => new Tuple<Guid, IList<BaseItem>>(i.Id, i.RootFolder.GetRecursiveChildren(i, null))) + var items = _libraryManager.RootFolder.RecursiveChildren + .SelectMany(i => i.Studios) + .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); - var masterDictionary = new Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>>(StringComparer.OrdinalIgnoreCase); - progress.Report(2); - var numComplete = 0; + var count = items.Count; - foreach (var lib in userLibraries) + foreach (var name in items) { - SetItemCounts(lib.Item1, lib.Item2, masterDictionary); - - numComplete++; - double percent = numComplete; - percent /= userLibraries.Count; - percent *= 8; - - progress.Report(percent); - } + cancellationToken.ThrowIfCancellationRequested(); - progress.Report(10); - - var count = masterDictionary.Count; - numComplete = 0; - - foreach (var name in masterDictionary.Keys) - { try { - await UpdateItemByNameCounts(name, cancellationToken, masterDictionary[name]).ConfigureAwait(false); + var itemByName = _libraryManager.GetStudio(name); + + await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -81,7 +65,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } catch (Exception ex) { - _logger.ErrorException("Error updating counts for {0}", ex, name); + _logger.ErrorException("Error refreshing {0}", ex, name); } numComplete++; @@ -94,32 +78,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators progress.Report(100); } - - private Task UpdateItemByNameCounts(string name, CancellationToken cancellationToken, Dictionary<Guid, Dictionary<CountType, int>> counts) - { - var itemByName = _libraryManager.GetStudio(name); - - foreach (var libraryId in counts.Keys) - { - var itemCounts = CountHelpers.GetCounts(counts[libraryId]); - - itemByName.SetItemByNameCounts(libraryId, itemCounts); - } - - return itemByName.RefreshMetadata(cancellationToken); - } - - private void SetItemCounts(Guid userId, IEnumerable<BaseItem> allItems, Dictionary<string, Dictionary<Guid, Dictionary<CountType, int>>> masterDictionary) - { - foreach (var media in allItems) - { - var names = media - .Studios - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToList(); - - CountHelpers.SetItemCounts(userId, media, names, masterDictionary); - } - } } } |
