< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.Validators.PeopleValidator
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 4
Coverable lines: 4
Total lines: 120
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using System.Threading;
 4using System.Threading.Tasks;
 5using Jellyfin.Data.Enums;
 6using MediaBrowser.Controller.Entities;
 7using MediaBrowser.Controller.Library;
 8using MediaBrowser.Controller.Providers;
 9using MediaBrowser.Model.IO;
 10using Microsoft.Extensions.Logging;
 11
 12namespace Emby.Server.Implementations.Library.Validators;
 13
 14/// <summary>
 15/// Class PeopleValidator.
 16/// </summary>
 17public class PeopleValidator
 18{
 19    /// <summary>
 20    /// The _library manager.
 21    /// </summary>
 22    private readonly ILibraryManager _libraryManager;
 23
 24    /// <summary>
 25    /// The _logger.
 26    /// </summary>
 27    private readonly ILogger _logger;
 28
 29    private readonly IFileSystem _fileSystem;
 30
 31    /// <summary>
 32    /// Initializes a new instance of the <see cref="PeopleValidator" /> class.
 33    /// </summary>
 34    /// <param name="libraryManager">The library manager.</param>
 35    /// <param name="logger">The logger.</param>
 36    /// <param name="fileSystem">The file system.</param>
 37    public PeopleValidator(ILibraryManager libraryManager, ILogger logger, IFileSystem fileSystem)
 38    {
 039        _libraryManager = libraryManager;
 040        _logger = logger;
 041        _fileSystem = fileSystem;
 042    }
 43
 44    /// <summary>
 45    /// Validates the people.
 46    /// </summary>
 47    /// <param name="cancellationToken">The cancellation token.</param>
 48    /// <param name="progress">The progress.</param>
 49    /// <returns>Task.</returns>
 50    public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
 51    {
 52        var people = _libraryManager.GetPeopleNames(new InternalPeopleQuery());
 53
 54        var numComplete = 0;
 55
 56        var numPeople = people.Count;
 57
 58        IProgress<double> subProgress = new Progress<double>((val) => progress.Report(val / 2));
 59
 60        _logger.LogDebug("Will refresh {Amount} people", numPeople);
 61
 62        foreach (var person in people)
 63        {
 64            cancellationToken.ThrowIfCancellationRequested();
 65
 66            try
 67            {
 68                var item = _libraryManager.GetPerson(person);
 69                if (item is null)
 70                {
 71                    _logger.LogWarning("Failed to get person: {Name}", person);
 72                    continue;
 73                }
 74
 75                var options = new MetadataRefreshOptions(new DirectoryService(_fileSystem))
 76                {
 77                    ImageRefreshMode = MetadataRefreshMode.ValidationOnly,
 78                    MetadataRefreshMode = MetadataRefreshMode.ValidationOnly
 79                };
 80
 81                await item.RefreshMetadata(options, cancellationToken).ConfigureAwait(false);
 82            }
 83            catch (OperationCanceledException)
 84            {
 85                throw;
 86            }
 87            catch (Exception ex)
 88            {
 89                _logger.LogError(ex, "Error validating IBN entry {Person}", person);
 90            }
 91
 92            // Update progress
 93            numComplete++;
 94            double percent = numComplete;
 95            percent /= numPeople;
 96
 97            subProgress.Report(100 * percent);
 98        }
 99
 100        var deadEntities = _libraryManager.GetItemList(new InternalItemsQuery
 101        {
 102            IncludeItemTypes = [BaseItemKind.Person],
 103            IsDeadPerson = true,
 104            IsLocked = false
 105        });
 106
 107        subProgress = new Progress<double>((val) => progress.Report((val / 2) + 50));
 108
 109        var i = 0;
 110        foreach (var item in deadEntities.Chunk(500))
 111        {
 112            _libraryManager.DeleteItemsUnsafeFast(item);
 113            subProgress.Report(100f / deadEntities.Count * (i++ * 100));
 114        }
 115
 116        progress.Report(100);
 117
 118        _logger.LogInformation("People validation complete");
 119    }
 120}