< Summary - Jellyfin

Information
Class: Jellyfin.Api.Controllers.StudiosController
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Controllers/StudiosController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 44
Coverable lines: 44
Total lines: 157
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
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%
GetStudios(...)0%4260%
GetStudio(...)0%620%

File(s)

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

#LineLine coverage
 1using System;
 2using System.ComponentModel.DataAnnotations;
 3using Jellyfin.Api.Extensions;
 4using Jellyfin.Api.Helpers;
 5using Jellyfin.Api.ModelBinders;
 6using Jellyfin.Data.Entities;
 7using Jellyfin.Data.Enums;
 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/// Studios controller.
 23/// </summary>
 24[Authorize]
 25public class StudiosController : BaseJellyfinApiController
 26{
 27    private readonly ILibraryManager _libraryManager;
 28    private readonly IUserManager _userManager;
 29    private readonly IDtoService _dtoService;
 30
 31    /// <summary>
 32    /// Initializes a new instance of the <see cref="StudiosController"/> class.
 33    /// </summary>
 34    /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
 35    /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
 36    /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
 037    public StudiosController(
 038        ILibraryManager libraryManager,
 039        IUserManager userManager,
 040        IDtoService dtoService)
 41    {
 042        _libraryManager = libraryManager;
 043        _userManager = userManager;
 044        _dtoService = dtoService;
 045    }
 46
 47    /// <summary>
 48    /// Gets all studios from a given item, folder, or the entire library.
 49    /// </summary>
 50    /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped fr
 51    /// <param name="limit">Optional. The maximum number of records to return.</param>
 52    /// <param name="searchTerm">Optional. Search term.</param>
 53    /// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</
 54    /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
 55    /// <param name="excludeItemTypes">Optional. If specified, results will be filtered out based on item type. This all
 56    /// <param name="includeItemTypes">Optional. If specified, results will be filtered based on item type. This allows 
 57    /// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
 58    /// <param name="enableUserData">Optional, include user data.</param>
 59    /// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
 60    /// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
 61    /// <param name="userId">User id.</param>
 62    /// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a gi
 63    /// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</p
 64    /// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</
 65    /// <param name="enableImages">Optional, include image information in output.</param>
 66    /// <param name="enableTotalRecordCount">Total record count.</param>
 67    /// <response code="200">Studios returned.</response>
 68    /// <returns>An <see cref="OkResult"/> containing the studios.</returns>
 69    [HttpGet]
 70    [ProducesResponseType(StatusCodes.Status200OK)]
 71    public ActionResult<QueryResult<BaseItemDto>> GetStudios(
 72        [FromQuery] int? startIndex,
 73        [FromQuery] int? limit,
 74        [FromQuery] string? searchTerm,
 75        [FromQuery] Guid? parentId,
 76        [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
 77        [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] excludeItemTypes,
 78        [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
 79        [FromQuery] bool? isFavorite,
 80        [FromQuery] bool? enableUserData,
 81        [FromQuery] int? imageTypeLimit,
 82        [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes,
 83        [FromQuery] Guid? userId,
 84        [FromQuery] string? nameStartsWithOrGreater,
 85        [FromQuery] string? nameStartsWith,
 86        [FromQuery] string? nameLessThan,
 87        [FromQuery] bool? enableImages = true,
 88        [FromQuery] bool enableTotalRecordCount = true)
 89    {
 090        userId = RequestHelpers.GetUserId(User, userId);
 091        var dtoOptions = new DtoOptions { Fields = fields }
 092            .AddClientFields(User)
 093            .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
 94
 095        User? user = userId.IsNullOrEmpty()
 096            ? null
 097            : _userManager.GetUserById(userId.Value);
 98
 099        var parentItem = _libraryManager.GetParentItem(parentId, userId);
 100
 0101        var query = new InternalItemsQuery(user)
 0102        {
 0103            ExcludeItemTypes = excludeItemTypes,
 0104            IncludeItemTypes = includeItemTypes,
 0105            StartIndex = startIndex,
 0106            Limit = limit,
 0107            IsFavorite = isFavorite,
 0108            NameLessThan = nameLessThan,
 0109            NameStartsWith = nameStartsWith,
 0110            NameStartsWithOrGreater = nameStartsWithOrGreater,
 0111            DtoOptions = dtoOptions,
 0112            SearchTerm = searchTerm,
 0113            EnableTotalRecordCount = enableTotalRecordCount
 0114        };
 115
 0116        if (parentId.HasValue)
 117        {
 0118            if (parentItem is Folder)
 119            {
 0120                query.AncestorIds = new[] { parentId.Value };
 121            }
 122            else
 123            {
 0124                query.ItemIds = new[] { parentId.Value };
 125            }
 126        }
 127
 0128        var result = _libraryManager.GetStudios(query);
 0129        var shouldIncludeItemTypes = includeItemTypes.Length != 0;
 0130        return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, shouldIncludeItemTypes, user);
 131    }
 132
 133    /// <summary>
 134    /// Gets a studio by name.
 135    /// </summary>
 136    /// <param name="name">Studio name.</param>
 137    /// <param name="userId">Optional. Filter by user id, and attach user data.</param>
 138    /// <response code="200">Studio returned.</response>
 139    /// <returns>An <see cref="OkResult"/> containing the studio.</returns>
 140    [HttpGet("{name}")]
 141    [ProducesResponseType(StatusCodes.Status200OK)]
 142    public ActionResult<BaseItemDto> GetStudio([FromRoute, Required] string name, [FromQuery] Guid? userId)
 143    {
 0144        userId = RequestHelpers.GetUserId(User, userId);
 0145        var dtoOptions = new DtoOptions().AddClientFields(User);
 146
 0147        var item = _libraryManager.GetStudio(name);
 0148        if (!userId.IsNullOrEmpty())
 149        {
 0150            var user = _userManager.GetUserById(userId.Value);
 151
 0152            return _dtoService.GetBaseItemDto(item, dtoOptions, user);
 153        }
 154
 0155        return _dtoService.GetBaseItemDto(item, dtoOptions);
 156    }
 157}