2015-01-17 11:15:09 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-09-10 11:56:00 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Validators
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class ArtistsValidator
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ArtistsValidator
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _library manager
|
|
|
|
|
/// </summary>
|
2013-09-16 19:08:18 -07:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-09-10 11:56:00 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _logger
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="ArtistsPostScanTask" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
2015-01-17 11:15:09 -07:00
|
|
|
|
public ArtistsValidator(ILibraryManager libraryManager, ILogger logger)
|
2013-09-10 11:56:00 -07:00
|
|
|
|
{
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Runs the specified progress.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="progress">The progress.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2015-01-24 23:34:50 -07:00
|
|
|
|
var allSongs = _libraryManager.RootFolder
|
|
|
|
|
.GetRecursiveChildren(i => !i.IsFolder && (i is IHasArtist))
|
|
|
|
|
.Cast<IHasArtist>()
|
|
|
|
|
.ToList();
|
2013-09-10 11:56:00 -07:00
|
|
|
|
|
2015-08-05 18:21:18 -07:00
|
|
|
|
var allArtists = _libraryManager.GetArtists(allSongs).ToList();
|
2013-09-10 11:56:00 -07:00
|
|
|
|
|
|
|
|
|
var numComplete = 0;
|
2013-09-19 17:53:18 -07:00
|
|
|
|
var numArtists = allArtists.Count;
|
2013-09-10 11:56:00 -07:00
|
|
|
|
|
2015-08-05 18:21:18 -07:00
|
|
|
|
foreach (var artistItem in allArtists)
|
2013-09-10 11:56:00 -07:00
|
|
|
|
{
|
2013-09-25 15:36:48 -07:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2013-09-10 11:56:00 -07:00
|
|
|
|
|
2013-09-25 15:36:48 -07:00
|
|
|
|
try
|
2013-09-10 11:56:00 -07:00
|
|
|
|
{
|
2013-09-25 15:36:48 -07:00
|
|
|
|
await artistItem.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
2015-08-05 18:21:18 -07:00
|
|
|
|
_logger.ErrorException("Error validating Artist {0}", ex, artistItem.Name);
|
2013-09-25 15:36:48 -07:00
|
|
|
|
}
|
2013-09-10 11:56:00 -07:00
|
|
|
|
|
2013-09-25 15:36:48 -07:00
|
|
|
|
// Update progress
|
|
|
|
|
numComplete++;
|
|
|
|
|
double percent = numComplete;
|
|
|
|
|
percent /= numArtists;
|
2013-09-10 11:56:00 -07:00
|
|
|
|
|
2013-09-25 15:36:48 -07:00
|
|
|
|
progress.Report(100 * percent);
|
2013-09-10 11:56:00 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|