< 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: 385
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 5/11/2026 - 12:15:59 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: 42110/29/2026 - 12:17:11 AM Line coverage: 0% (0/8) Total lines: 385 5/11/2026 - 12:15:59 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        // Asking for a type filter has always implied wanting that type's counts back.
 130        if (includeItemTypes.Length != 0 && !dtoOptions.ContainsField(ItemFields.ItemCounts))
 131        {
 132            dtoOptions.Fields = [.. dtoOptions.Fields, ItemFields.ItemCounts];
 133        }
 134
 135        User? user = null;
 136        BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId);
 137
 138        if (!userId.IsNullOrEmpty())
 139        {
 140            user = _userManager.GetUserById(userId.Value);
 141        }
 142
 143        var query = new InternalItemsQuery(user)
 144        {
 145            ExcludeItemTypes = excludeItemTypes,
 146            IncludeItemTypes = includeItemTypes,
 147            MediaTypes = mediaTypes,
 148            StartIndex = startIndex,
 149            Limit = limit,
 150            IsFavorite = isFavorite,
 151            NameLessThan = nameLessThan,
 152            NameStartsWith = nameStartsWith,
 153            NameStartsWithOrGreater = nameStartsWithOrGreater,
 154            Tags = tags,
 155            OfficialRatings = officialRatings,
 156            Genres = genres,
 157            GenreIds = genreIds,
 158            StudioIds = studioIds,
 159            Person = person,
 160            PersonIds = personIds,
 161            PersonTypes = personTypes,
 162            Years = years,
 163            MinCommunityRating = minCommunityRating,
 164            DtoOptions = dtoOptions,
 165            SearchTerm = searchTerm,
 166            EnableTotalRecordCount = enableTotalRecordCount,
 167            OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder)
 168        };
 169
 170        if (parentId.HasValue)
 171        {
 172            if (parentItem is Folder)
 173            {
 174                query.AncestorIds = new[] { parentId.Value };
 175            }
 176            else
 177            {
 178                query.ItemIds = new[] { parentId.Value };
 179            }
 180        }
 181
 182        // Studios
 183        if (studios.Length != 0)
 184        {
 185            query.StudioIds = studios.Select(i =>
 186            {
 187                try
 188                {
 189                    return _libraryManager.GetStudio(i);
 190                }
 191                catch
 192                {
 193                    return null;
 194                }
 195            }).Where(i => i is not null).Select(i => i!.Id).ToArray();
 196        }
 197
 198        query.ApplyFilters(filters);
 199
 200        var result = _libraryManager.GetArtists(query);
 201
 202        return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, user);
 203    }
 204
 205    /// <summary>
 206    /// Gets all album artists from a given item, folder, or the entire library.
 207    /// </summary>
 208    /// <param name="minCommunityRating">Optional filter by minimum community rating.</param>
 209    /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped fr
 210    /// <param name="limit">Optional. The maximum number of records to return.</param>
 211    /// <param name="searchTerm">Optional. Search term.</param>
 212    /// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</
 213    /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
 214    /// <param name="excludeItemTypes">Optional. If specified, results will be filtered out based on item type. This all
 215    /// <param name="includeItemTypes">Optional. If specified, results will be filtered based on item type. This allows 
 216    /// <param name="filters">Optional. Specify additional filters to apply.</param>
 217    /// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
 218    /// <param name="mediaTypes">Optional filter by MediaType. Allows multiple, comma delimited.</param>
 219    /// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe
 220    /// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple,
 221    /// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This all
 222    /// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe del
 223    /// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multi
 224    /// <param name="enableUserData">Optional, include user data.</param>
 225    /// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
 226    /// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
 227    /// <param name="person">Optional. If specified, results will be filtered to include only those containing the speci
 228    /// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the sp
 229    /// <param name="personTypes">Optional. If specified, along with Person, results will be filtered to include only th
 230    /// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pi
 231    /// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multipl
 232    /// <param name="userId">User id.</param>
 233    /// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a gi
 234    /// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</p
 235    /// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</
 236    /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited.</param>
 237    /// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
 238    /// <param name="enableImages">Optional, include image information in output.</param>
 239    /// <param name="enableTotalRecordCount">Total record count.</param>
 240    /// <response code="200">Album artists returned.</response>
 241    /// <returns>An <see cref="OkResult"/> containing the album artists.</returns>
 242    [HttpGet("AlbumArtists")]
 243    [ProducesResponseType(StatusCodes.Status200OK)]
 244    [Obsolete("Use GetPersons")]
 245    public ActionResult<QueryResult<BaseItemDto>> GetAlbumArtists(
 246        [FromQuery] double? minCommunityRating,
 247        [FromQuery] int? startIndex,
 248        [FromQuery] int? limit,
 249        [FromQuery] string? searchTerm,
 250        [FromQuery] Guid? parentId,
 251        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields,
 252        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] BaseItemKind[] excludeItemTypes,
 253        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] BaseItemKind[] includeItemTypes,
 254        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFilter[] filters,
 255        [FromQuery] bool? isFavorite,
 256        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] MediaType[] mediaTypes,
 257        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] genres,
 258        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] genreIds,
 259        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] officialRatings,
 260        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] tags,
 261        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] int[] years,
 262        [FromQuery] bool? enableUserData,
 263        [FromQuery] int? imageTypeLimit,
 264        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes,
 265        [FromQuery] string? person,
 266        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] personIds,
 267        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] string[] personTypes,
 268        [FromQuery, ModelBinder(typeof(PipeDelimitedCollectionModelBinder))] string[] studios,
 269        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] studioIds,
 270        [FromQuery] Guid? userId,
 271        [FromQuery] string? nameStartsWithOrGreater,
 272        [FromQuery] string? nameStartsWith,
 273        [FromQuery] string? nameLessThan,
 274        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemSortBy[] sortBy,
 275        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] SortOrder[] sortOrder,
 276        [FromQuery] bool? enableImages = true,
 277        [FromQuery] bool enableTotalRecordCount = true)
 278    {
 279        userId = RequestHelpers.GetUserId(User, userId);
 280        var dtoOptions = new DtoOptions { Fields = fields }
 281            .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
 282
 283        // Asking for a type filter has always implied wanting that type's counts back.
 284        if (includeItemTypes.Length != 0 && !dtoOptions.ContainsField(ItemFields.ItemCounts))
 285        {
 286            dtoOptions.Fields = [.. dtoOptions.Fields, ItemFields.ItemCounts];
 287        }
 288
 289        User? user = null;
 290        BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId);
 291
 292        if (!userId.IsNullOrEmpty())
 293        {
 294            user = _userManager.GetUserById(userId.Value);
 295        }
 296
 297        var query = new InternalItemsQuery(user)
 298        {
 299            ExcludeItemTypes = excludeItemTypes,
 300            IncludeItemTypes = includeItemTypes,
 301            MediaTypes = mediaTypes,
 302            StartIndex = startIndex,
 303            Limit = limit,
 304            IsFavorite = isFavorite,
 305            NameLessThan = nameLessThan,
 306            NameStartsWith = nameStartsWith,
 307            NameStartsWithOrGreater = nameStartsWithOrGreater,
 308            Tags = tags,
 309            OfficialRatings = officialRatings,
 310            Genres = genres,
 311            GenreIds = genreIds,
 312            StudioIds = studioIds,
 313            Person = person,
 314            PersonIds = personIds,
 315            PersonTypes = personTypes,
 316            Years = years,
 317            MinCommunityRating = minCommunityRating,
 318            DtoOptions = dtoOptions,
 319            SearchTerm = searchTerm,
 320            EnableTotalRecordCount = enableTotalRecordCount,
 321            OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder)
 322        };
 323
 324        if (parentId.HasValue)
 325        {
 326            if (parentItem is Folder)
 327            {
 328                query.AncestorIds = new[] { parentId.Value };
 329            }
 330            else
 331            {
 332                query.ItemIds = new[] { parentId.Value };
 333            }
 334        }
 335
 336        // Studios
 337        if (studios.Length != 0)
 338        {
 339            query.StudioIds = studios.Select(i =>
 340            {
 341                try
 342                {
 343                    return _libraryManager.GetStudio(i);
 344                }
 345                catch
 346                {
 347                    return null;
 348                }
 349            }).Where(i => i is not null).Select(i => i!.Id).ToArray();
 350        }
 351
 352        query.ApplyFilters(filters);
 353
 354        var result = _libraryManager.GetAlbumArtists(query);
 355
 356        return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, user);
 357    }
 358
 359    /// <summary>
 360    /// Gets an artist by name.
 361    /// </summary>
 362    /// <param name="name">Studio name.</param>
 363    /// <param name="userId">Optional. Filter by user id, and attach user data.</param>
 364    /// <response code="200">Artist returned.</response>
 365    /// <returns>An <see cref="OkResult"/> containing the artist.</returns>
 366    [HttpGet("{name}")]
 367    [ProducesResponseType(StatusCodes.Status200OK)]
 368    [Obsolete("Use GetPerson")]
 369    public ActionResult<BaseItemDto> GetArtistByName([FromRoute, Required] string name, [FromQuery] Guid? userId)
 370    {
 371        userId = RequestHelpers.GetUserId(User, userId);
 372        var dtoOptions = new DtoOptions();
 373
 374        var item = _libraryManager.GetArtist(name, dtoOptions);
 375
 376        if (!userId.IsNullOrEmpty())
 377        {
 378            var user = _userManager.GetUserById(userId.Value);
 379
 380            return _dtoService.GetBaseItemDto(item, dtoOptions, user);
 381        }
 382
 383        return _dtoService.GetBaseItemDto(item, dtoOptions);
 384    }
 385}