< 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: 127
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.Globalization;
 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>
 17    public 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            _logger.LogDebug("Will refresh {0} people", numPeople);
 59
 60            foreach (var person in people)
 61            {
 62                cancellationToken.ThrowIfCancellationRequested();
 63
 64                try
 65                {
 66                    var item = _libraryManager.GetPerson(person);
 67                    if (item is null)
 68                    {
 69                        _logger.LogWarning("Failed to get person: {Name}", person);
 70                        continue;
 71                    }
 72
 73                    var options = new MetadataRefreshOptions(new DirectoryService(_fileSystem))
 74                    {
 75                        ImageRefreshMode = MetadataRefreshMode.ValidationOnly,
 76                        MetadataRefreshMode = MetadataRefreshMode.ValidationOnly
 77                    };
 78
 79                    await item.RefreshMetadata(options, cancellationToken).ConfigureAwait(false);
 80                }
 81                catch (OperationCanceledException)
 82                {
 83                    throw;
 84                }
 85                catch (Exception ex)
 86                {
 87                    _logger.LogError(ex, "Error validating IBN entry {Person}", person);
 88                }
 89
 90                // Update progress
 91                numComplete++;
 92                double percent = numComplete;
 93                percent /= numPeople;
 94
 95                progress.Report(100 * percent);
 96            }
 97
 98            var deadEntities = _libraryManager.GetItemList(new InternalItemsQuery
 99            {
 100                IncludeItemTypes = [BaseItemKind.Person],
 101                IsDeadPerson = true,
 102                IsLocked = false
 103            });
 104
 105            foreach (var item in deadEntities)
 106            {
 107                _logger.LogInformation(
 108                    "Deleting dead {2} {0} {1}.",
 109                    item.Id.ToString("N", CultureInfo.InvariantCulture),
 110                    item.Name,
 111                    item.GetType().Name);
 112
 113                _libraryManager.DeleteItem(
 114                    item,
 115                    new DeleteOptions
 116                    {
 117                        DeleteFileLocation = false
 118                    },
 119                    false);
 120            }
 121
 122            progress.Report(100);
 123
 124            _logger.LogInformation("People validation complete");
 125        }
 126    }
 127}