diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/Validators')
7 files changed, 55 insertions, 361 deletions
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); - } - } } } |
