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