< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.Plugins.Tmdb.People.TmdbPersonProvider
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonProvider.cs
Line coverage
60%
Covered lines: 3
Uncovered lines: 2
Coverable lines: 5
Total lines: 148
Line coverage: 60%
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 11/15/2025 - 12:10:12 AM Line coverage: 60% (3/5) Total lines: 1442/19/2026 - 12:13:41 AM Line coverage: 60% (3/5) Total lines: 148

Metrics

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

File(s)

/srv/git/jellyfin/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonProvider.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Globalization;
 4using System.Net.Http;
 5using System.Threading;
 6using System.Threading.Tasks;
 7using MediaBrowser.Common.Net;
 8using MediaBrowser.Controller.Entities;
 9using MediaBrowser.Controller.Providers;
 10using MediaBrowser.Model.Entities;
 11using MediaBrowser.Model.Providers;
 12
 13namespace MediaBrowser.Providers.Plugins.Tmdb.People
 14{
 15    /// <summary>
 16    /// Person image provider powered by TMDb.
 17    /// </summary>
 18    public class TmdbPersonProvider : IRemoteMetadataProvider<Person, PersonLookupInfo>
 19    {
 20        private readonly IHttpClientFactory _httpClientFactory;
 21        private readonly TmdbClientManager _tmdbClientManager;
 22
 23        /// <summary>
 24        /// Initializes a new instance of the <see cref="TmdbPersonProvider"/> class.
 25        /// </summary>
 26        /// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param>
 27        /// <param name="tmdbClientManager">The <see cref="TmdbClientManager"/>.</param>
 28        public TmdbPersonProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
 29        {
 2130            _httpClientFactory = httpClientFactory;
 2131            _tmdbClientManager = tmdbClientManager;
 2132        }
 33
 34        /// <inheritdoc />
 035        public string Name => TmdbUtils.ProviderName;
 36
 37        /// <inheritdoc />
 38        public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(PersonLookupInfo searchInfo, CancellationTok
 39        {
 40            if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId))
 41            {
 42                var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.Invariant
 43
 44                if (personResult is not null)
 45                {
 46                    var result = new RemoteSearchResult
 47                    {
 48                        Name = personResult.Name,
 49                        SearchProviderName = Name,
 50                        Overview = personResult.Biography
 51                    };
 52
 53                    if (personResult.Images?.Profiles is not null && personResult.Images.Profiles.Count > 0)
 54                    {
 55                        result.ImageUrl = _tmdbClientManager.GetProfileUrl(personResult.Images.Profiles[0].FilePath);
 56                    }
 57
 58                    result.SetProviderId(MetadataProvider.Tmdb, personResult.Id.ToString(CultureInfo.InvariantCulture));
 59                    result.TrySetProviderId(MetadataProvider.Imdb, personResult.ExternalIds?.ImdbId);
 60
 61                    return [result];
 62                }
 63            }
 64
 65            var personSearchResult = await _tmdbClientManager.SearchPersonAsync(searchInfo.Name, cancellationToken).Conf
 66            if (personSearchResult is null)
 67            {
 68                return [];
 69            }
 70
 71            var remoteSearchResults = new RemoteSearchResult[personSearchResult.Count];
 72            for (var i = 0; i < personSearchResult.Count; i++)
 73            {
 74                var person = personSearchResult[i];
 75                var remoteSearchResult = new RemoteSearchResult
 76                {
 77                    SearchProviderName = Name,
 78                    Name = person.Name,
 79                    ImageUrl = _tmdbClientManager.GetProfileUrl(person.ProfilePath)
 80                };
 81
 82                remoteSearchResult.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture)
 83                remoteSearchResults[i] = remoteSearchResult;
 84            }
 85
 86            return remoteSearchResults;
 87        }
 88
 89        /// <inheritdoc />
 90        public async Task<MetadataResult<Person>> GetMetadata(PersonLookupInfo info, CancellationToken cancellationToken
 91        {
 92            var personTmdbId = Convert.ToInt32(info.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
 93
 94            // We don't already have an Id, need to fetch it
 95            if (personTmdbId <= 0)
 96            {
 97                var personSearchResults = await _tmdbClientManager.SearchPersonAsync(info.Name, cancellationToken).Confi
 98                if (personSearchResults?.Count > 0)
 99                {
 100                    personTmdbId = personSearchResults[0].Id;
 101                }
 102            }
 103
 104            var result = new MetadataResult<Person>();
 105
 106            if (personTmdbId > 0)
 107            {
 108                var person = await _tmdbClientManager.GetPersonAsync(personTmdbId, info.MetadataLanguage, info.MetadataC
 109                if (person is null)
 110                {
 111                    return result;
 112                }
 113
 114                result.HasMetadata = true;
 115
 116                var item = new Person
 117                {
 118                    // Take name from incoming info, don't rename the person
 119                    // TODO: This should go in PersonMetadataService, not each person provider
 120                    Name = info.Name,
 121                    HomePageUrl = person.Homepage,
 122                    Overview = person.Biography,
 123                    PremiereDate = person.Birthday?.ToUniversalTime(),
 124                    EndDate = person.Deathday?.ToUniversalTime()
 125                };
 126
 127                if (!string.IsNullOrWhiteSpace(person.PlaceOfBirth))
 128                {
 129                    item.ProductionLocations = new[] { person.PlaceOfBirth };
 130                }
 131
 132                item.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
 133                item.TrySetProviderId(MetadataProvider.Imdb, person.ImdbId);
 134
 135                result.HasMetadata = true;
 136                result.Item = item;
 137            }
 138
 139            return result;
 140        }
 141
 142        /// <inheritdoc />
 143        public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
 144        {
 0145            return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
 146        }
 147    }
 148}