2015-01-17 18:15:09 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-09-10 18:56:00 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-08-06 04:38:01 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-09-10 18:56:00 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Validators
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class ArtistsValidator
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ArtistsValidator
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _library manager
|
|
|
|
|
/// </summary>
|
2013-09-17 02:08:18 +00:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-09-10 18:56:00 +00: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 18:15:09 +00:00
|
|
|
|
public ArtistsValidator(ILibraryManager libraryManager, ILogger logger)
|
2013-09-10 18:56:00 +00: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)
|
|
|
|
|
{
|
2016-08-06 04:38:01 +00:00
|
|
|
|
var items = _libraryManager.GetAllArtists(new InternalItemsQuery())
|
|
|
|
|
.Items
|
|
|
|
|
.Select(i => i.Item1)
|
2015-01-25 06:34:50 +00:00
|
|
|
|
.ToList();
|
2013-09-10 18:56:00 +00:00
|
|
|
|
|
|
|
|
|
var numComplete = 0;
|
2016-08-06 04:38:01 +00:00
|
|
|
|
var count = items.Count;
|
2013-09-10 18:56:00 +00:00
|
|
|
|
|
2016-08-06 04:38:01 +00:00
|
|
|
|
foreach (var item in items)
|
2013-09-10 18:56:00 +00:00
|
|
|
|
{
|
2013-09-25 22:36:48 +00:00
|
|
|
|
try
|
2013-09-10 18:56:00 +00:00
|
|
|
|
{
|
2016-08-06 04:38:01 +00:00
|
|
|
|
await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
2013-09-25 22:36:48 +00:00
|
|
|
|
}
|
2016-08-06 04:38:01 +00:00
|
|
|
|
catch (OperationCanceledException)
|
2013-09-25 22:36:48 +00:00
|
|
|
|
{
|
2016-08-06 04:38:01 +00:00
|
|
|
|
// Don't clutter the log
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error refreshing {0}", ex, item.Name);
|
2013-09-25 22:36:48 +00:00
|
|
|
|
}
|
2013-09-10 18:56:00 +00:00
|
|
|
|
|
2013-09-25 22:36:48 +00:00
|
|
|
|
numComplete++;
|
|
|
|
|
double percent = numComplete;
|
2016-08-06 04:38:01 +00:00
|
|
|
|
percent /= count;
|
|
|
|
|
percent *= 100;
|
2013-09-10 18:56:00 +00:00
|
|
|
|
|
2016-08-06 04:38:01 +00:00
|
|
|
|
progress.Report(percent);
|
2013-09-10 18:56:00 +00:00
|
|
|
|
}
|
2016-08-06 04:38:01 +00:00
|
|
|
|
|
|
|
|
|
progress.Report(100);
|
2013-09-10 18:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|