using MediaBrowser.Common.Progress; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Entities; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace MediaBrowser.Providers.Music { /// /// Class ArtistsPostScanTask /// public class ArtistsPostScanTask : ILibraryPostScanTask { /// /// The _library manager /// private readonly ILibraryManager _libraryManager; /// /// Initializes a new instance of the class. /// /// The library manager. public ArtistsPostScanTask(ILibraryManager libraryManager) { _libraryManager = libraryManager; } /// /// Runs the specified progress. /// /// The progress. /// The cancellation token. /// Task. public async Task Run(IProgress progress, CancellationToken cancellationToken) { var allItems = _libraryManager.RootFolder.RecursiveChildren.ToList(); var allArtists = await GetAllArtists(allItems).ConfigureAwait(false); progress.Report(10); var allMusicArtists = allItems.OfType().ToList(); var numComplete = 0; foreach (var artist in allArtists) { var musicArtist = FindMusicArtist(artist, allMusicArtists); if (musicArtist != null) { artist.Images = new Dictionary(musicArtist.Images); artist.BackdropImagePaths = musicArtist.BackdropImagePaths.ToList(); artist.ScreenshotImagePaths = musicArtist.ScreenshotImagePaths.ToList(); artist.SetProviderId(MetadataProviders.Musicbrainz, musicArtist.GetProviderId(MetadataProviders.Musicbrainz)); } numComplete++; double percent = numComplete; percent /= allArtists.Length; percent *= 5; progress.Report(10 + percent); } var innerProgress = new ActionableProgress(); innerProgress.RegisterAction(pct => progress.Report(15 + pct * .85)); await _libraryManager.ValidateArtists(cancellationToken, innerProgress).ConfigureAwait(false); } /// /// Gets all artists. /// /// All items. /// Task{Artist[]}. private Task GetAllArtists(IEnumerable allItems) { var itemsList = allItems.OfType