< Summary - Jellyfin

Information
Class: Jellyfin.Api.Controllers.ArtistsController
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Controllers/ArtistsController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 421
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 2/14/2026 - 12:11:17 AM Line coverage: 0% (0/199) Branch coverage: 0% (0/44) Total lines: 4813/14/2026 - 12:13:58 AM Line coverage: 0% (0/165) Branch coverage: 0% (0/18) Total lines: 4174/27/2026 - 12:15:04 AM Line coverage: 0% (0/165) Branch coverage: 0% (0/18) Total lines: 4185/14/2026 - 12:15:54 AM Line coverage: 0% (0/8) Total lines: 421 2/14/2026 - 12:11:17 AM Line coverage: 0% (0/199) Branch coverage: 0% (0/44) Total lines: 4813/14/2026 - 12:13:58 AM Line coverage: 0% (0/165) Branch coverage: 0% (0/18) Total lines: 4174/27/2026 - 12:15:04 AM Line coverage: 0% (0/165) Branch coverage: 0% (0/18) Total lines: 418

Coverage delta

Coverage delta 1 -1

Metrics

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

File(s)

/srv/git/jellyfin/Jellyfin.Api/Controllers/ArtistsController.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.Data.Enums;
 8using Jellyfin.Database.Implementations.Entities;
 9using Jellyfin.Database.Implementations.Enums;
 10using Jellyfin.Extensions;
 11using MediaBrowser.Controller.Dto;
 12using MediaBrowser.Controller.Entities;
 13using MediaBrowser.Controller.Library;
 14using MediaBrowser.Model.Dto;
 15using MediaBrowser.Model.Entities;
 16using MediaBrowser.Model.Querying;
 17using Microsoft.AspNetCore.Authorization;
 18using Microsoft.AspNetCore.Http;
 19using Microsoft.AspNetCore.Mvc;
 20
 21namespace Jellyfin.Api.Controllers;
 22
 23/// <summary>
 24/// The artists controller.
 25/// </summary>
 26[Route("Artists")]
 27[Authorize]
 28[Tags("Artist")]
 29public class ArtistsController : BaseJellyfinApiController
 30{
 31    private readonly ILibraryManager _libraryManager;
 32    private readonly IUserManager _userManager;
 33    private readonly IDtoService _dtoService;
 34
 35    /// <summary>
 36    /// Initializes a new instance of the <see cref="ArtistsController"/> class.
 37    /// </summary>
 38    /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
 39    /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
 40    /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
 041    public ArtistsController(
 042        ILibraryManager libraryManager,
 043        IUserManager userManager,
 044        IDtoService dtoService)
 45    {
 046        _libraryManager = libraryManager;
 047        _userManager = userManager;
 048        _dtoService = dtoService;
 049    }
 50
 51    /// <summary>
 52    /// Gets all artists from a given item, folder, or the entire library.
 53    /// </summary>
 54    /// <param name="minCommunityRating">Optional filter by minimum community rating.</param>
 55    /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped fr
 56    /// <param name="limit">Optional. The maximum number of records to return.</param>
 57    /// <param name="searchTerm">Optional. Search term.</param>
 58    /// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</
 59    /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
 60    /// <param name="excludeItemTypes">Optional. If specified, results will be filtered out based on item type. This all
 61    /// <param name="includeItemTypes">Optional. If specified, results will be filtered based on item type. This allows 
 62    /// <param name="filters">Optional. Specify additional filters to apply.</param>
 63    /// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
 64    /// <param name="mediaTypes">Optional filter by MediaType. Allows multiple, comma delimited.</param>
 65    /// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe
 66    /// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple,
 67    /// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This all
 68    /// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe del
 69    /// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multi
 70    /// <param name="enableUserData">Optional, include user data.</param>
 71    /// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
 72    /// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
 73    /// <param name="person">Optional. If specified, results will be filtered to include only those containing the speci
 74    /// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the sp
 75    /// <param name="personTypes">Optional. If specified, along with Person, results will be filtered to include only th
 76    /// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pi
 77    /// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multipl
 78    /// <param name="userId">User id.</param>
 79    /// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a gi
 80    /// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</p
 81    /// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</
 82    /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited.</param>
 83    /// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
 84    /// <param name="enableImages">Optional, include image information in output.</param>
 85    /// <param name="enableTotalRecordCount">Total record count.</param>
 86    /// <response code="200">Artists returned.</response>
 87    /// <returns>An <see cref="OkResult"/> containing the artists.</returns>
 88    [HttpGet]
 89    [ProducesResponseType(StatusCodes.Status200OK)]
 90    [Obsolete("Use GetPersons")]
 91    public ActionResult<QueryResult<BaseItemDto>> GetArtists(
 92        [FromQuery] double? minCommunityRating,
 93        [FromQuery] int? startIndex,
 94        [FromQuery] int? limit,
 95        [FromQuery] string? searchTerm,
 96        [FromQuery] Guid? parentId,
 97        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields,
 98        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] BaseItemKind[] excludeItemTypes,
 99        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] BaseItemKind[] includeItemTypes,
 100        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFilter[] filters,
 101        [FromQuery] bool? isFavorite,
 102        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] MediaType[] mediaTypes,
 103        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] genres,
 104        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] genreIds,
 105        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] officialRatings,
 106        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] tags,
 107        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] int[] years,
 108        [FromQuery] bool? enableUserData,
 109        [FromQuery] int? imageTypeLimit,
 110        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes,
 111        [FromQuery] string? person,
 112        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] personIds,
 113        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] string[] personTypes,
 114        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] studios,
 115        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] studioIds,
 116        [FromQuery] Guid? userId,
 117        [FromQuery] string? nameStartsWithOrGreater,
 118        [FromQuery] string? nameStartsWith,
 119        [FromQuery] string? nameLessThan,
 120        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemSortBy[] sortBy,
 121        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] SortOrder[] sortOrder,
 122        [FromQuery] bool? enableImages = true,
 123        [FromQuery] bool enableTotalRecordCount = true)
 124    {
 125        userId = RequestHelpers.GetUserId(User, userId);
 126        var dtoOptions = new DtoOptions { Fields = fields }
 127            .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
 128
 129        User? user = null;
 130        BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId);
 131
 132        if (!userId.IsNullOrEmpty())
 133        {
 134            user = _userManager.GetUserById(userId.Value);
 135        }
 136
 137        var query = new InternalItemsQuery(user)
 138        {
 139            ExcludeItemTypes = excludeItemTypes,
 140            IncludeItemTypes = includeItemTypes,
 141            MediaTypes = mediaTypes,
 142            StartIndex = startIndex,
 143            Limit = limit,
 144            IsFavorite = isFavorite,
 145            NameLessThan = nameLessThan,
 146            NameStartsWith = nameStartsWith,
 147            NameStartsWithOrGreater = nameStartsWithOrGreater,
 148            Tags = tags,
 149            OfficialRatings = officialRatings,
 150            Genres = genres,
 151            GenreIds = genreIds,
 152            StudioIds = studioIds,
 153            Person = person,
 154            PersonIds = personIds,
 155            PersonTypes = personTypes,
 156            Years = years,
 157            MinCommunityRating = minCommunityRating,
 158            DtoOptions = dtoOptions,
 159            SearchTerm = searchTerm,
 160            EnableTotalRecordCount = enableTotalRecordCount,
 161            OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder)
 162        };
 163
 164        if (parentId.HasValue)
 165        {
 166            if (parentItem is Folder)
 167            {
 168                query.AncestorIds = new[] { parentId.Value };
 169            }
 170            else
 171            {
 172                query.ItemIds = new[] { parentId.Value };
 173            }
 174        }
 175
 176        // Studios
 177        if (studios.Length != 0)
 178        {
 179            query.StudioIds = studios.Select(i =>
 180            {
 181                try
 182                {
 183                    return _libraryManager.GetStudio(i);
 184                }
 185                catch
 186                {
 187                    return null;
 188                }
 189            }).Where(i => i is not null).Select(i => i!.Id).ToArray();
 190        }
 191
 192        query.ApplyFilters(filters);
 193
 194        var result = _libraryManager.GetArtists(query);
 195
 196        var dtos = result.Items.Select(i =>
 197        {
 198            var (baseItem, itemCounts) = i;
 199            var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user);
 200
 201            if (includeItemTypes.Length != 0)
 202            {
 203                dto.ChildCount = itemCounts.ItemCount;
 204                dto.ProgramCount = itemCounts.ProgramCount;
 205                dto.SeriesCount = itemCounts.SeriesCount;
 206                dto.EpisodeCount = itemCounts.EpisodeCount;
 207                dto.MovieCount = itemCounts.MovieCount;
 208                dto.TrailerCount = itemCounts.TrailerCount;
 209                dto.AlbumCount = itemCounts.AlbumCount;
 210                dto.SongCount = itemCounts.SongCount;
 211                dto.ArtistCount = itemCounts.ArtistCount;
 212            }
 213
 214            return dto;
 215        });
 216
 217        return new QueryResult<BaseItemDto>(
 218            query.StartIndex,
 219            result.TotalRecordCount,
 220            dtos.ToArray());
 221    }
 222
 223    /// <summary>
 224    /// Gets all album artists from a given item, folder, or the entire library.
 225    /// </summary>
 226    /// <param name="minCommunityRating">Optional filter by minimum community rating.</param>
 227    /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped fr
 228    /// <param name="limit">Optional. The maximum number of records to return.</param>
 229    /// <param name="searchTerm">Optional. Search term.</param>
 230    /// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</
 231    /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
 232    /// <param name="excludeItemTypes">Optional. If specified, results will be filtered out based on item type. This all
 233    /// <param name="includeItemTypes">Optional. If specified, results will be filtered based on item type. This allows 
 234    /// <param name="filters">Optional. Specify additional filters to apply.</param>
 235    /// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
 236    /// <param name="mediaTypes">Optional filter by MediaType. Allows multiple, comma delimited.</param>
 237    /// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe
 238    /// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple,
 239    /// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This all
 240    /// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe del
 241    /// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multi
 242    /// <param name="enableUserData">Optional, include user data.</param>
 243    /// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
 244    /// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
 245    /// <param name="person">Optional. If specified, results will be filtered to include only those containing the speci
 246    /// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the sp
 247    /// <param name="personTypes">Optional. If specified, along with Person, results will be filtered to include only th
 248    /// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pi
 249    /// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multipl
 250    /// <param name="userId">User id.</param>
 251    /// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a gi
 252    /// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</p
 253    /// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</
 254    /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited.</param>
 255    /// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
 256    /// <param name="enableImages">Optional, include image information in output.</param>
 257    /// <param name="enableTotalRecordCount">Total record count.</param>
 258    /// <response code="200">Album artists returned.</response>
 259    /// <returns>An <see cref="OkResult"/> containing the album artists.</returns>
 260    [HttpGet("AlbumArtists")]
 261    [ProducesResponseType(StatusCodes.Status200OK)]
 262    [Obsolete("Use GetPersons")]
 263    public ActionResult<QueryResult<BaseItemDto>> GetAlbumArtists(
 264        [FromQuery] double? minCommunityRating,
 265        [FromQuery] int? startIndex,
 266        [FromQuery] int? limit,
 267        [FromQuery] string? searchTerm,
 268        [FromQuery] Guid? parentId,
 269        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields,
 270        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] BaseItemKind[] excludeItemTypes,
 271        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] BaseItemKind[] includeItemTypes,
 272        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFilter[] filters,
 273        [FromQuery] bool? isFavorite,
 274        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] MediaType[] mediaTypes,
 275        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] genres,
 276        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] genreIds,
 277        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] officialRatings,
 278        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] tags,
 279        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] int[] years,
 280        [FromQuery] bool? enableUserData,
 281        [FromQuery] int? imageTypeLimit,
 282        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes,
 283        [FromQuery] string? person,
 284        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] personIds,
 285        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] string[] personTypes,
 286        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] studios,
 287        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] studioIds,
 288        [FromQuery] Guid? userId,
 289        [FromQuery] string? nameStartsWithOrGreater,
 290        [FromQuery] string? nameStartsWith,
 291        [FromQuery] string? nameLessThan,
 292        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemSortBy[] sortBy,
 293        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] SortOrder[] sortOrder,
 294        [FromQuery] bool? enableImages = true,
 295        [FromQuery] bool enableTotalRecordCount = true)
 296    {
 297        userId = RequestHelpers.GetUserId(User, userId);
 298        var dtoOptions = new DtoOptions { Fields = fields }
 299            .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
 300
 301        User? user = null;
 302        BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId);
 303
 304        if (!userId.IsNullOrEmpty())
 305        {
 306            user = _userManager.GetUserById(userId.Value);
 307        }
 308
 309        var query = new InternalItemsQuery(user)
 310        {
 311            ExcludeItemTypes = excludeItemTypes,
 312            IncludeItemTypes = includeItemTypes,
 313            MediaTypes = mediaTypes,
 314            StartIndex = startIndex,
 315            Limit = limit,
 316            IsFavorite = isFavorite,
 317            NameLessThan = nameLessThan,
 318            NameStartsWith = nameStartsWith,
 319            NameStartsWithOrGreater = nameStartsWithOrGreater,
 320            Tags = tags,
 321            OfficialRatings = officialRatings,
 322            Genres = genres,
 323            GenreIds = genreIds,
 324            StudioIds = studioIds,
 325            Person = person,
 326            PersonIds = personIds,
 327            PersonTypes = personTypes,
 328            Years = years,
 329            MinCommunityRating = minCommunityRating,
 330            DtoOptions = dtoOptions,
 331            SearchTerm = searchTerm,
 332            EnableTotalRecordCount = enableTotalRecordCount,
 333            OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder)
 334        };
 335
 336        if (parentId.HasValue)
 337        {
 338            if (parentItem is Folder)
 339            {
 340                query.AncestorIds = new[] { parentId.Value };
 341            }
 342            else
 343            {
 344                query.ItemIds = new[] { parentId.Value };
 345            }
 346        }
 347
 348        // Studios
 349        if (studios.Length != 0)
 350        {
 351            query.StudioIds = studios.Select(i =>
 352            {
 353                try
 354                {
 355                    return _libraryManager.GetStudio(i);
 356                }
 357                catch
 358                {
 359                    return null;
 360                }
 361            }).Where(i => i is not null).Select(i => i!.Id).ToArray();
 362        }
 363
 364        query.ApplyFilters(filters);
 365
 366        var result = _libraryManager.GetAlbumArtists(query);
 367
 368        var dtos = result.Items.Select(i =>
 369        {
 370            var (baseItem, itemCounts) = i;
 371            var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user);
 372
 373            if (includeItemTypes.Length != 0)
 374            {
 375                dto.ChildCount = itemCounts.ItemCount;
 376                dto.ProgramCount = itemCounts.ProgramCount;
 377                dto.SeriesCount = itemCounts.SeriesCount;
 378                dto.EpisodeCount = itemCounts.EpisodeCount;
 379                dto.MovieCount = itemCounts.MovieCount;
 380                dto.TrailerCount = itemCounts.TrailerCount;
 381                dto.AlbumCount = itemCounts.AlbumCount;
 382                dto.SongCount = itemCounts.SongCount;
 383                dto.ArtistCount = itemCounts.ArtistCount;
 384            }
 385
 386            return dto;
 387        });
 388
 389        return new QueryResult<BaseItemDto>(
 390            query.StartIndex,
 391            result.TotalRecordCount,
 392            dtos.ToArray());
 393    }
 394
 395    /// <summary>
 396    /// Gets an artist by name.
 397    /// </summary>
 398    /// <param name="name">Studio name.</param>
 399    /// <param name="userId">Optional. Filter by user id, and attach user data.</param>
 400    /// <response code="200">Artist returned.</response>
 401    /// <returns>An <see cref="OkResult"/> containing the artist.</returns>
 402    [HttpGet("{name}")]
 403    [ProducesResponseType(StatusCodes.Status200OK)]
 404    [Obsolete("Use GetPerson")]
 405    public ActionResult<BaseItemDto> GetArtistByName([FromRoute, Required] string name, [FromQuery] Guid? userId)
 406    {
 407        userId = RequestHelpers.GetUserId(User, userId);
 408        var dtoOptions = new DtoOptions();
 409
 410        var item = _libraryManager.GetArtist(name, dtoOptions);
 411
 412        if (!userId.IsNullOrEmpty())
 413        {
 414            var user = _userManager.GetUserById(userId.Value);
 415
 416            return _dtoService.GetBaseItemDto(item, dtoOptions, user);
 417        }
 418
 419        return _dtoService.GetBaseItemDto(item, dtoOptions);
 420    }
 421}