2019-01-13 12:54:44 -07:00
|
|
|
using System;
|
2019-01-13 12:21:32 -07:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-08-14 06:24:30 -07:00
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-10-13 10:52:57 -07:00
|
|
|
using MediaBrowser.Controller.Library;
|
2014-03-09 15:14:44 -07:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2016-10-25 12:02:04 -07:00
|
|
|
using MediaBrowser.Model.IO;
|
2019-01-13 12:21:32 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-10-13 10:52:57 -07:00
|
|
|
|
2016-11-02 23:37:52 -07:00
|
|
|
namespace Emby.Server.Implementations.Library.Validators
|
2013-10-13 10:52:57 -07:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Class PeopleValidator
|
|
|
|
/// </summary>
|
|
|
|
public class PeopleValidator
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The _library manager
|
|
|
|
/// </summary>
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
/// <summary>
|
|
|
|
/// The _logger
|
|
|
|
/// </summary>
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
2014-08-14 06:24:30 -07:00
|
|
|
private readonly IServerConfigurationManager _config;
|
2015-09-13 16:07:54 -07:00
|
|
|
private readonly IFileSystem _fileSystem;
|
2014-08-14 06:24:30 -07:00
|
|
|
|
2013-10-13 10:52:57 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="PeopleValidator" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
|
|
|
/// <param name="logger">The logger.</param>
|
2015-09-13 16:07:54 -07:00
|
|
|
public PeopleValidator(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem)
|
2013-10-13 10:52:57 -07:00
|
|
|
{
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
_logger = logger;
|
2014-08-14 06:24:30 -07:00
|
|
|
_config = config;
|
2015-09-13 16:07:54 -07:00
|
|
|
_fileSystem = fileSystem;
|
2014-08-14 06:24:30 -07:00
|
|
|
}
|
|
|
|
|
2013-10-13 10:52:57 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Validates the people.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
/// <param name="progress">The progress.</param>
|
|
|
|
/// <returns>Task.</returns>
|
2014-08-14 06:24:30 -07:00
|
|
|
public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
|
2013-10-13 10:52:57 -07:00
|
|
|
{
|
2017-08-09 12:56:38 -07:00
|
|
|
var people = _libraryManager.GetPeopleNames(new InternalPeopleQuery());
|
2014-08-14 06:24:30 -07:00
|
|
|
|
|
|
|
var numComplete = 0;
|
2016-08-03 21:38:58 -07:00
|
|
|
|
2017-08-09 12:56:38 -07:00
|
|
|
var numPeople = people.Count;
|
2016-08-03 21:38:58 -07:00
|
|
|
|
2018-12-13 06:18:25 -07:00
|
|
|
_logger.LogDebug("Will refresh {0} people", numPeople);
|
2016-08-07 14:57:46 -07:00
|
|
|
|
2017-08-09 12:56:38 -07:00
|
|
|
foreach (var person in people)
|
2013-10-13 10:52:57 -07:00
|
|
|
{
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-08-09 12:56:38 -07:00
|
|
|
var item = _libraryManager.GetPerson(person);
|
2014-08-14 06:24:30 -07:00
|
|
|
|
2018-12-14 12:17:29 -07:00
|
|
|
var options = new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
|
2016-11-18 01:39:20 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
ImageRefreshMode = MetadataRefreshMode.ValidationOnly,
|
2016-11-18 01:39:20 -07:00
|
|
|
MetadataRefreshMode = MetadataRefreshMode.ValidationOnly
|
|
|
|
};
|
2013-10-13 10:52:57 -07:00
|
|
|
|
2014-03-09 15:14:44 -07:00
|
|
|
await item.RefreshMetadata(options, cancellationToken).ConfigureAwait(false);
|
2013-10-13 10:52:57 -07:00
|
|
|
}
|
2015-10-04 20:24:24 -07:00
|
|
|
catch (OperationCanceledException)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
2013-10-13 10:52:57 -07:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error validating IBN entry {person}", person);
|
2013-10-13 10:52:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update progress
|
|
|
|
numComplete++;
|
|
|
|
double percent = numComplete;
|
2016-08-07 14:57:46 -07:00
|
|
|
percent /= numPeople;
|
2013-10-13 10:52:57 -07:00
|
|
|
|
2014-05-29 07:19:12 -07:00
|
|
|
progress.Report(100 * percent);
|
2013-10-13 10:52:57 -07:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
var deadEntities = _libraryManager.GetItemList(new InternalItemsQuery
|
|
|
|
{
|
|
|
|
IncludeItemTypes = new[] { typeof(Person).Name },
|
|
|
|
IsDeadPerson = true,
|
|
|
|
IsLocked = false
|
|
|
|
});
|
|
|
|
|
|
|
|
foreach (var item in deadEntities)
|
|
|
|
{
|
2018-12-13 06:18:25 -07:00
|
|
|
_logger.LogInformation("Deleting dead {2} {0} {1}.", item.Id.ToString("N"), item.Name, item.GetType().Name);
|
2018-09-12 10:26:21 -07:00
|
|
|
|
|
|
|
_libraryManager.DeleteItem(item, new DeleteOptions
|
|
|
|
{
|
|
|
|
DeleteFileLocation = false
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
2013-10-13 10:52:57 -07:00
|
|
|
progress.Report(100);
|
|
|
|
|
2018-12-13 06:18:25 -07:00
|
|
|
_logger.LogInformation("People validation complete");
|
2013-10-13 10:52:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|