< Summary - Jellyfin

Information
Class: Jellyfin.Api.Controllers.ChannelsController
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Controllers/ChannelsController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 190
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 12/27/2025 - 12:11:51 AM Line coverage: 0% (0/6) Total lines: 2543/14/2026 - 12:13:58 AM Line coverage: 0% (0/6) Total lines: 190

Coverage delta

Coverage delta 1 -1

Metrics

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

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel.DataAnnotations;
 4using System.Threading;
 5using System.Threading.Tasks;
 6using Jellyfin.Api.Helpers;
 7using Jellyfin.Api.ModelBinders;
 8using Jellyfin.Data.Enums;
 9using Jellyfin.Database.Implementations.Enums;
 10using Jellyfin.Extensions;
 11using MediaBrowser.Controller.Channels;
 12using MediaBrowser.Controller.Dto;
 13using MediaBrowser.Controller.Entities;
 14using MediaBrowser.Controller.Library;
 15using MediaBrowser.Model.Channels;
 16using MediaBrowser.Model.Dto;
 17using MediaBrowser.Model.Querying;
 18using Microsoft.AspNetCore.Authorization;
 19using Microsoft.AspNetCore.Http;
 20using Microsoft.AspNetCore.Mvc;
 21
 22namespace Jellyfin.Api.Controllers;
 23
 24/// <summary>
 25/// Channels Controller.
 26/// </summary>
 27[Authorize]
 28public class ChannelsController : BaseJellyfinApiController
 29{
 30    private readonly IChannelManager _channelManager;
 31    private readonly IUserManager _userManager;
 32
 33    /// <summary>
 34    /// Initializes a new instance of the <see cref="ChannelsController"/> class.
 35    /// </summary>
 36    /// <param name="channelManager">Instance of the <see cref="IChannelManager"/> interface.</param>
 37    /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
 038    public ChannelsController(IChannelManager channelManager, IUserManager userManager)
 39    {
 040        _channelManager = channelManager;
 041        _userManager = userManager;
 042    }
 43
 44    /// <summary>
 45    /// Gets available channels.
 46    /// </summary>
 47    /// <param name="userId">User Id to filter by. Use <see cref="Guid.Empty"/> to not filter by user.</param>
 48    /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped fr
 49    /// <param name="limit">Optional. The maximum number of records to return.</param>
 50    /// <param name="supportsLatestItems">Optional. Filter by channels that support getting latest items.</param>
 51    /// <param name="supportsMediaDeletion">Optional. Filter by channels that support media deletion.</param>
 52    /// <param name="isFavorite">Optional. Filter by channels that are favorite.</param>
 53    /// <response code="200">Channels returned.</response>
 54    /// <returns>An <see cref="OkResult"/> containing the channels.</returns>
 55    [HttpGet]
 56    [ProducesResponseType(StatusCodes.Status200OK)]
 57    public async Task<ActionResult<QueryResult<BaseItemDto>>> GetChannels(
 58        [FromQuery] Guid? userId,
 59        [FromQuery] int? startIndex,
 60        [FromQuery] int? limit,
 61        [FromQuery] bool? supportsLatestItems,
 62        [FromQuery] bool? supportsMediaDeletion,
 63        [FromQuery] bool? isFavorite)
 64    {
 65        userId = RequestHelpers.GetUserId(User, userId);
 66        return await _channelManager.GetChannelsAsync(new ChannelQuery
 67        {
 68            Limit = limit,
 69            StartIndex = startIndex,
 70            UserId = userId.Value,
 71            SupportsLatestItems = supportsLatestItems,
 72            SupportsMediaDeletion = supportsMediaDeletion,
 73            IsFavorite = isFavorite
 74        }).ConfigureAwait(false);
 75    }
 76
 77    /// <summary>
 78    /// Get all channel features.
 79    /// </summary>
 80    /// <response code="200">All channel features returned.</response>
 81    /// <returns>An <see cref="OkResult"/> containing the channel features.</returns>
 82    [HttpGet("Features")]
 83    [ProducesResponseType(StatusCodes.Status200OK)]
 84    public ActionResult<IEnumerable<ChannelFeatures>> GetAllChannelFeatures()
 85    {
 086        return _channelManager.GetAllChannelFeatures();
 87    }
 88
 89    /// <summary>
 90    /// Get channel features.
 91    /// </summary>
 92    /// <param name="channelId">Channel id.</param>
 93    /// <response code="200">Channel features returned.</response>
 94    /// <returns>An <see cref="OkResult"/> containing the channel features.</returns>
 95    [HttpGet("{channelId}/Features")]
 96    public ActionResult<ChannelFeatures> GetChannelFeatures([FromRoute, Required] Guid channelId)
 97    {
 098        return _channelManager.GetChannelFeatures(channelId);
 99    }
 100
 101    /// <summary>
 102    /// Get channel items.
 103    /// </summary>
 104    /// <param name="channelId">Channel Id.</param>
 105    /// <param name="folderId">Optional. Folder Id.</param>
 106    /// <param name="userId">Optional. User Id.</param>
 107    /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped fr
 108    /// <param name="limit">Optional. The maximum number of records to return.</param>
 109    /// <param name="sortOrder">Optional. Sort Order - Ascending,Descending.</param>
 110    /// <param name="filters">Optional. Specify additional filters to apply.</param>
 111    /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited. Options: Album, AlbumArtist, Ar
 112    /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
 113    /// <response code="200">Channel items returned.</response>
 114    /// <returns>
 115    /// A <see cref="Task"/> representing the request to get the channel items.
 116    /// The task result contains an <see cref="OkResult"/> containing the channel items.
 117    /// </returns>
 118    [HttpGet("{channelId}/Items")]
 119    public async Task<ActionResult<QueryResult<BaseItemDto>>> GetChannelItems(
 120        [FromRoute, Required] Guid channelId,
 121        [FromQuery] Guid? folderId,
 122        [FromQuery] Guid? userId,
 123        [FromQuery] int? startIndex,
 124        [FromQuery] int? limit,
 125        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] SortOrder[] sortOrder,
 126        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFilter[] filters,
 127        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemSortBy[] sortBy,
 128        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields)
 129    {
 130        userId = RequestHelpers.GetUserId(User, userId);
 131        var user = userId.IsNullOrEmpty()
 132            ? null
 133            : _userManager.GetUserById(userId.Value);
 134
 135        var query = new InternalItemsQuery(user)
 136        {
 137            Limit = limit,
 138            StartIndex = startIndex,
 139            ChannelIds = [channelId],
 140            ParentId = folderId ?? Guid.Empty,
 141            OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder),
 142            DtoOptions = new DtoOptions { Fields = fields }
 143        };
 144
 145        query.ApplyFilters(filters);
 146
 147        return await _channelManager.GetChannelItems(query, CancellationToken.None).ConfigureAwait(false);
 148    }
 149
 150    /// <summary>
 151    /// Gets latest channel items.
 152    /// </summary>
 153    /// <param name="userId">Optional. User Id.</param>
 154    /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped fr
 155    /// <param name="limit">Optional. The maximum number of records to return.</param>
 156    /// <param name="filters">Optional. Specify additional filters to apply.</param>
 157    /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
 158    /// <param name="channelIds">Optional. Specify one or more channel id's, comma delimited.</param>
 159    /// <response code="200">Latest channel items returned.</response>
 160    /// <returns>
 161    /// A <see cref="Task"/> representing the request to get the latest channel items.
 162    /// The task result contains an <see cref="OkResult"/> containing the latest channel items.
 163    /// </returns>
 164    [HttpGet("Items/Latest")]
 165    public async Task<ActionResult<QueryResult<BaseItemDto>>> GetLatestChannelItems(
 166        [FromQuery] Guid? userId,
 167        [FromQuery] int? startIndex,
 168        [FromQuery] int? limit,
 169        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFilter[] filters,
 170        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields,
 171        [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] channelIds)
 172    {
 173        userId = RequestHelpers.GetUserId(User, userId);
 174        var user = userId.IsNullOrEmpty()
 175            ? null
 176            : _userManager.GetUserById(userId.Value);
 177
 178        var query = new InternalItemsQuery(user)
 179        {
 180            Limit = limit,
 181            StartIndex = startIndex,
 182            ChannelIds = channelIds,
 183            DtoOptions = new DtoOptions { Fields = fields }
 184        };
 185
 186        query.ApplyFilters(filters);
 187
 188        return await _channelManager.GetLatestChannelItems(query, CancellationToken.None).ConfigureAwait(false);
 189    }
 190}