< Summary - Jellyfin

Information
Class: Jellyfin.Api.Controllers.PersonsController
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Controllers/PersonsController.cs
Line coverage
28%
Covered lines: 13
Uncovered lines: 32
Coverable lines: 45
Total lines: 157
Line coverage: 28.8%
Branch coverage
10%
Covered branches: 1
Total branches: 10
Branch coverage: 10%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 1/23/2026 - 12:11:06 AM Line coverage: 34.2% (13/38) Branch coverage: 10% (1/10) Total lines: 1394/6/2026 - 12:13:55 AM Line coverage: 32.5% (13/40) Branch coverage: 10% (1/10) Total lines: 1454/14/2026 - 12:13:23 AM Line coverage: 30.2% (13/43) Branch coverage: 10% (1/10) Total lines: 1544/27/2026 - 12:15:04 AM Line coverage: 30.2% (13/43) Branch coverage: 10% (1/10) Total lines: 1555/5/2026 - 12:15:44 AM Line coverage: 28.8% (13/45) Branch coverage: 10% (1/10) Total lines: 157 1/23/2026 - 12:11:06 AM Line coverage: 34.2% (13/38) Branch coverage: 10% (1/10) Total lines: 1394/6/2026 - 12:13:55 AM Line coverage: 32.5% (13/40) Branch coverage: 10% (1/10) Total lines: 1454/14/2026 - 12:13:23 AM Line coverage: 30.2% (13/43) Branch coverage: 10% (1/10) Total lines: 1544/27/2026 - 12:15:04 AM Line coverage: 30.2% (13/43) Branch coverage: 10% (1/10) Total lines: 1555/5/2026 - 12:15:44 AM Line coverage: 28.8% (13/45) Branch coverage: 10% (1/10) Total lines: 157

Coverage delta

Coverage delta 3 -3

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetPersons(...)0%4260%
GetPerson(...)25%5455.55%

File(s)

/srv/git/jellyfin/Jellyfin.Api/Controllers/PersonsController.cs

#LineLine coverage
 1using System;
 2using System.ComponentModel.DataAnnotations;
 3using System.Linq;
 4using Jellyfin.Api.Extensions;
 5using Jellyfin.Api.Helpers;
 6using Jellyfin.Api.ModelBinders;
 7using Jellyfin.Database.Implementations.Entities;
 8using Jellyfin.Extensions;
 9using MediaBrowser.Controller.Dto;
 10using MediaBrowser.Controller.Entities;
 11using MediaBrowser.Controller.Library;
 12using MediaBrowser.Model.Dto;
 13using MediaBrowser.Model.Entities;
 14using MediaBrowser.Model.Querying;
 15using Microsoft.AspNetCore.Authorization;
 16using Microsoft.AspNetCore.Http;
 17using Microsoft.AspNetCore.Mvc;
 18
 19namespace Jellyfin.Api.Controllers;
 20
 21/// <summary>
 22/// Persons controller.
 23/// </summary>
 24[Authorize]
 25[Tags("Person")]
 26public class PersonsController : BaseJellyfinApiController
 27{
 28    private readonly ILibraryManager _libraryManager;
 29    private readonly IDtoService _dtoService;
 30    private readonly IUserManager _userManager;
 31
 32    /// <summary>
 33    /// Initializes a new instance of the <see cref="PersonsController"/> class.
 34    /// </summary>
 35    /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
 36    /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
 37    /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
 138    public PersonsController(
 139        ILibraryManager libraryManager,
 140        IDtoService dtoService,
 141        IUserManager userManager)
 42    {
 143        _libraryManager = libraryManager;
 144        _dtoService = dtoService;
 145        _userManager = userManager;
 146    }
 47
 48    /// <summary>
 49    /// Gets all persons.
 50    /// </summary>
 51    /// <param name="startIndex">Optional. All items with a lower index will be dropped from the response.</param>
 52    /// <param name="limit">Optional. The maximum number of records to return.</param>
 53    /// <param name="searchTerm">The search term.</param>
 54    /// <param name="nameStartsWith">Optional. Filter by items whose name starts with the given input string.</param>
 55    /// <param name="nameLessThan">Optional. Filter by items whose name will appear before this value when sorted alphab
 56    /// <param name="nameStartsWithOrGreater">Optional. Filter by items whose name will appear after this value when sor
 57    /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
 58    /// <param name="filters">Optional. Specify additional filters to apply.</param>
 59    /// <param name="isFavorite">Optional filter by items that are marked as favorite, or not. userId is required.</para
 60    /// <param name="enableUserData">Optional, include user data.</param>
 61    /// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
 62    /// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
 63    /// <param name="excludePersonTypes">Optional. If specified results will be filtered to exclude those containing the
 64    /// <param name="personTypes">Optional. If specified results will be filtered to include only those containing the s
 65    /// <param name="parentId">Optional. Specify this to localize the search to a specific library. Omit to use the root
 66    /// <param name="appearsInItemId">Optional. If specified, person results will be filtered on items related to said p
 67    /// <param name="userId">User id.</param>
 68    /// <param name="enableImages">Optional, include image information in output.</param>
 69    /// <response code="200">Persons returned.</response>
 70    /// <returns>An <see cref="OkResult"/> containing the queryresult of persons.</returns>
 71    [HttpGet]
 72    [ProducesResponseType(StatusCodes.Status200OK)]
 73    public ActionResult<QueryResult<BaseItemDto>> GetPersons(
 74        [FromQuery] int? startIndex,
 75        [FromQuery] int? limit,
 76        [FromQuery] string? searchTerm,
 77        [FromQuery] string? nameStartsWith,
 78        [FromQuery] string? nameLessThan,
 79        [FromQuery] string? nameStartsWithOrGreater,
 80        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields,
 81        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFilter[] filters,
 82        [FromQuery] bool? isFavorite,
 83        [FromQuery] bool? enableUserData,
 84        [FromQuery] int? imageTypeLimit,
 85        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes,
 86        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] string[] excludePersonTypes,
 87        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] string[] personTypes,
 88        [FromQuery] Guid? parentId,
 89        [FromQuery] Guid? appearsInItemId,
 90        [FromQuery] Guid? userId,
 91        [FromQuery] bool? enableImages = true)
 92    {
 093        userId = RequestHelpers.GetUserId(User, userId);
 094        var dtoOptions = new DtoOptions { Fields = fields }
 095            .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
 96
 097        User? user = userId.IsNullOrEmpty()
 098            ? null
 099            : _userManager.GetUserById(userId.Value);
 100
 0101        var isFavoriteInFilters = filters.Any(f => f == ItemFilter.IsFavorite);
 0102        var peopleItems = _libraryManager.GetPeopleItems(new InternalPeopleQuery(
 0103            personTypes,
 0104            excludePersonTypes)
 0105        {
 0106            NameContains = searchTerm,
 0107            NameStartsWith = nameStartsWith,
 0108            NameLessThan = nameLessThan,
 0109            NameStartsWithOrGreater = nameStartsWithOrGreater,
 0110            User = user,
 0111            IsFavorite = !isFavorite.HasValue && isFavoriteInFilters ? true : isFavorite,
 0112            AppearsInItemId = appearsInItemId ?? Guid.Empty,
 0113            ParentId = parentId,
 0114            StartIndex = startIndex,
 0115            Limit = limit ?? 0
 0116        });
 117
 0118        return new QueryResult<BaseItemDto>(
 0119            peopleItems.StartIndex,
 0120            peopleItems.TotalRecordCount,
 0121            peopleItems.Items
 0122                .Select(person => _dtoService.GetItemByNameDto(person, dtoOptions, null, user))
 0123                .ToArray());
 124    }
 125
 126    /// <summary>
 127    /// Get person by name.
 128    /// </summary>
 129    /// <param name="name">Person name.</param>
 130    /// <param name="userId">Optional. Filter by user id, and attach user data.</param>
 131    /// <response code="200">Person returned.</response>
 132    /// <response code="404">Person not found.</response>
 133    /// <returns>An <see cref="OkResult"/> containing the person on success,
 134    /// or a <see cref="NotFoundResult"/> if person not found.</returns>
 135    [HttpGet("{name}")]
 136    [ProducesResponseType(StatusCodes.Status200OK)]
 137    [ProducesResponseType(StatusCodes.Status404NotFound)]
 138    public ActionResult<BaseItemDto> GetPerson([FromRoute, Required] string name, [FromQuery] Guid? userId)
 139    {
 1140        userId = RequestHelpers.GetUserId(User, userId);
 1141        var dtoOptions = new DtoOptions();
 142
 1143        var item = _libraryManager.GetPerson(name);
 1144        if (item is null)
 145        {
 1146            return NotFound();
 147        }
 148
 0149        if (!userId.IsNullOrEmpty())
 150        {
 0151            var user = _userManager.GetUserById(userId.Value);
 0152            return _dtoService.GetBaseItemDto(item, dtoOptions, user);
 153        }
 154
 0155        return _dtoService.GetBaseItemDto(item, dtoOptions);
 156    }
 157}