2020-04-23 14:54:28 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2020-09-05 23:11:44 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-04-23 14:54:28 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-07-06 14:02:23 +00:00
|
|
|
using Jellyfin.Api.Constants;
|
2020-06-24 16:54:25 +00:00
|
|
|
using Jellyfin.Api.Extensions;
|
2020-05-24 18:33:16 +00:00
|
|
|
using Jellyfin.Api.Helpers;
|
2020-10-14 19:03:36 +00:00
|
|
|
using Jellyfin.Api.ModelBinders;
|
2020-04-23 14:54:28 +00:00
|
|
|
using MediaBrowser.Controller.Channels;
|
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Model.Channels;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Querying;
|
2020-05-19 15:47:02 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-04-23 14:54:28 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Channels Controller.
|
|
|
|
/// </summary>
|
2020-07-06 14:02:23 +00:00
|
|
|
[Authorize(Policy = Policies.DefaultAuthorization)]
|
2020-04-23 14:54:28 +00:00
|
|
|
public class ChannelsController : BaseJellyfinApiController
|
|
|
|
{
|
|
|
|
private readonly IChannelManager _channelManager;
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ChannelsController"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="channelManager">Instance of the <see cref="IChannelManager"/> interface.</param>
|
|
|
|
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
|
|
|
public ChannelsController(IChannelManager channelManager, IUserManager userManager)
|
|
|
|
{
|
|
|
|
_channelManager = channelManager;
|
|
|
|
_userManager = userManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets available channels.
|
|
|
|
/// </summary>
|
2020-05-24 18:19:26 +00:00
|
|
|
/// <param name="userId">User Id to filter by. Use <see cref="Guid.Empty"/> to not filter by user.</param>
|
2020-04-23 14:54:28 +00:00
|
|
|
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
|
|
|
/// <param name="supportsLatestItems">Optional. Filter by channels that support getting latest items.</param>
|
|
|
|
/// <param name="supportsMediaDeletion">Optional. Filter by channels that support media deletion.</param>
|
|
|
|
/// <param name="isFavorite">Optional. Filter by channels that are favorite.</param>
|
2020-05-19 15:47:02 +00:00
|
|
|
/// <response code="200">Channels returned.</response>
|
2020-05-24 18:19:26 +00:00
|
|
|
/// <returns>An <see cref="OkResult"/> containing the channels.</returns>
|
2020-04-23 14:54:28 +00:00
|
|
|
[HttpGet]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetChannels(
|
2020-07-07 15:10:51 +00:00
|
|
|
[FromQuery] Guid? userId,
|
2020-04-23 14:54:28 +00:00
|
|
|
[FromQuery] int? startIndex,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery] bool? supportsLatestItems,
|
|
|
|
[FromQuery] bool? supportsMediaDeletion,
|
|
|
|
[FromQuery] bool? isFavorite)
|
|
|
|
{
|
|
|
|
return _channelManager.GetChannels(new ChannelQuery
|
|
|
|
{
|
|
|
|
Limit = limit,
|
|
|
|
StartIndex = startIndex,
|
2020-07-07 15:10:51 +00:00
|
|
|
UserId = userId ?? Guid.Empty,
|
2020-04-23 14:54:28 +00:00
|
|
|
SupportsLatestItems = supportsLatestItems,
|
|
|
|
SupportsMediaDeletion = supportsMediaDeletion,
|
|
|
|
IsFavorite = isFavorite
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get all channel features.
|
|
|
|
/// </summary>
|
2020-05-19 15:47:02 +00:00
|
|
|
/// <response code="200">All channel features returned.</response>
|
2020-05-24 18:19:26 +00:00
|
|
|
/// <returns>An <see cref="OkResult"/> containing the channel features.</returns>
|
2020-04-23 14:54:28 +00:00
|
|
|
[HttpGet("Features")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-05-24 18:19:26 +00:00
|
|
|
public ActionResult<IEnumerable<ChannelFeatures>> GetAllChannelFeatures()
|
2020-04-23 14:54:28 +00:00
|
|
|
{
|
|
|
|
return _channelManager.GetAllChannelFeatures();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get channel features.
|
|
|
|
/// </summary>
|
2020-05-24 21:54:34 +00:00
|
|
|
/// <param name="channelId">Channel id.</param>
|
2020-05-19 15:47:02 +00:00
|
|
|
/// <response code="200">Channel features returned.</response>
|
2020-05-24 18:19:26 +00:00
|
|
|
/// <returns>An <see cref="OkResult"/> containing the channel features.</returns>
|
2020-05-24 21:54:34 +00:00
|
|
|
[HttpGet("{channelId}/Features")]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<ChannelFeatures> GetChannelFeatures([FromRoute, Required] string channelId)
|
2020-04-23 14:54:28 +00:00
|
|
|
{
|
2020-05-24 21:54:34 +00:00
|
|
|
return _channelManager.GetChannelFeatures(channelId);
|
2020-04-23 14:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get channel items.
|
|
|
|
/// </summary>
|
2020-05-24 21:54:34 +00:00
|
|
|
/// <param name="channelId">Channel Id.</param>
|
2020-05-24 18:19:26 +00:00
|
|
|
/// <param name="folderId">Optional. Folder Id.</param>
|
|
|
|
/// <param name="userId">Optional. User Id.</param>
|
2020-04-23 14:54:28 +00:00
|
|
|
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
2020-05-24 18:19:26 +00:00
|
|
|
/// <param name="sortOrder">Optional. Sort Order - Ascending,Descending.</param>
|
2020-10-09 23:41:17 +00:00
|
|
|
/// <param name="filters">Optional. Specify additional filters to apply.</param>
|
2020-04-23 14:54:28 +00:00
|
|
|
/// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, CriticRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime.</param>
|
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
|
2020-05-19 15:47:02 +00:00
|
|
|
/// <response code="200">Channel items returned.</response>
|
2020-07-06 14:02:23 +00:00
|
|
|
/// <returns>
|
|
|
|
/// A <see cref="Task"/> representing the request to get the channel items.
|
|
|
|
/// The task result contains an <see cref="OkResult"/> containing the channel items.
|
|
|
|
/// </returns>
|
2020-05-24 21:54:34 +00:00
|
|
|
[HttpGet("{channelId}/Items")]
|
2020-04-23 14:54:28 +00:00
|
|
|
public async Task<ActionResult<QueryResult<BaseItemDto>>> GetChannelItems(
|
2020-09-06 15:07:27 +00:00
|
|
|
[FromRoute, Required] Guid channelId,
|
2020-04-23 14:54:28 +00:00
|
|
|
[FromQuery] Guid? folderId,
|
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? startIndex,
|
|
|
|
[FromQuery] int? limit,
|
2020-05-24 22:01:53 +00:00
|
|
|
[FromQuery] string? sortOrder,
|
2020-10-14 19:03:36 +00:00
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter[] filters,
|
2020-05-24 22:01:53 +00:00
|
|
|
[FromQuery] string? sortBy,
|
|
|
|
[FromQuery] string? fields)
|
2020-04-23 14:54:28 +00:00
|
|
|
{
|
2020-07-07 15:10:51 +00:00
|
|
|
var user = userId.HasValue && !userId.Equals(Guid.Empty)
|
|
|
|
? _userManager.GetUserById(userId.Value)
|
|
|
|
: null;
|
2020-04-23 14:54:28 +00:00
|
|
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
{
|
|
|
|
Limit = limit,
|
|
|
|
StartIndex = startIndex,
|
2020-05-24 21:54:34 +00:00
|
|
|
ChannelIds = new[] { channelId },
|
2020-04-23 14:54:28 +00:00
|
|
|
ParentId = folderId ?? Guid.Empty,
|
2020-05-24 18:33:16 +00:00
|
|
|
OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder),
|
2020-06-24 16:54:25 +00:00
|
|
|
DtoOptions = new DtoOptions()
|
|
|
|
.AddItemFields(fields)
|
2020-04-23 14:54:28 +00:00
|
|
|
};
|
|
|
|
|
2020-10-09 23:41:17 +00:00
|
|
|
foreach (var filter in filters)
|
2020-04-23 14:54:28 +00:00
|
|
|
{
|
|
|
|
switch (filter)
|
|
|
|
{
|
|
|
|
case ItemFilter.IsFolder:
|
|
|
|
query.IsFolder = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsNotFolder:
|
|
|
|
query.IsFolder = false;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsUnplayed:
|
|
|
|
query.IsPlayed = false;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsPlayed:
|
|
|
|
query.IsPlayed = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsFavorite:
|
|
|
|
query.IsFavorite = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsResumable:
|
|
|
|
query.IsResumable = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.Likes:
|
|
|
|
query.IsLiked = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.Dislikes:
|
|
|
|
query.IsLiked = false;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsFavoriteOrLikes:
|
|
|
|
query.IsFavoriteOrLiked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return await _channelManager.GetChannelItems(query, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets latest channel items.
|
|
|
|
/// </summary>
|
2020-05-24 18:19:26 +00:00
|
|
|
/// <param name="userId">Optional. User Id.</param>
|
2020-04-23 14:54:28 +00:00
|
|
|
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
2020-10-09 23:41:17 +00:00
|
|
|
/// <param name="filters">Optional. Specify additional filters to apply.</param>
|
2020-04-23 14:54:28 +00:00
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
|
|
|
|
/// <param name="channelIds">Optional. Specify one or more channel id's, comma delimited.</param>
|
2020-05-19 15:47:02 +00:00
|
|
|
/// <response code="200">Latest channel items returned.</response>
|
2020-05-24 18:19:26 +00:00
|
|
|
/// <returns>
|
|
|
|
/// A <see cref="Task"/> representing the request to get the latest channel items.
|
|
|
|
/// The task result contains an <see cref="OkResult"/> containing the latest channel items.
|
|
|
|
/// </returns>
|
2020-05-24 00:19:49 +00:00
|
|
|
[HttpGet("Items/Latest")]
|
2020-04-23 14:54:28 +00:00
|
|
|
public async Task<ActionResult<QueryResult<BaseItemDto>>> GetLatestChannelItems(
|
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? startIndex,
|
|
|
|
[FromQuery] int? limit,
|
2020-10-14 19:03:36 +00:00
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter[] filters,
|
2020-07-07 15:10:51 +00:00
|
|
|
[FromQuery] string? fields,
|
|
|
|
[FromQuery] string? channelIds)
|
2020-04-23 14:54:28 +00:00
|
|
|
{
|
2020-07-07 15:10:51 +00:00
|
|
|
var user = userId.HasValue && !userId.Equals(Guid.Empty)
|
|
|
|
? _userManager.GetUserById(userId.Value)
|
|
|
|
: null;
|
2020-04-23 14:54:28 +00:00
|
|
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
{
|
|
|
|
Limit = limit,
|
|
|
|
StartIndex = startIndex,
|
2020-05-24 18:19:26 +00:00
|
|
|
ChannelIds = (channelIds ?? string.Empty)
|
|
|
|
.Split(',')
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i))
|
|
|
|
.Select(i => new Guid(i))
|
|
|
|
.ToArray(),
|
2020-06-24 16:54:25 +00:00
|
|
|
DtoOptions = new DtoOptions()
|
|
|
|
.AddItemFields(fields)
|
2020-04-23 14:54:28 +00:00
|
|
|
};
|
|
|
|
|
2020-10-09 23:41:17 +00:00
|
|
|
foreach (var filter in filters)
|
2020-04-23 14:54:28 +00:00
|
|
|
{
|
|
|
|
switch (filter)
|
|
|
|
{
|
|
|
|
case ItemFilter.IsFolder:
|
|
|
|
query.IsFolder = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsNotFolder:
|
|
|
|
query.IsFolder = false;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsUnplayed:
|
|
|
|
query.IsPlayed = false;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsPlayed:
|
|
|
|
query.IsPlayed = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsFavorite:
|
|
|
|
query.IsFavorite = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsResumable:
|
|
|
|
query.IsResumable = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.Likes:
|
|
|
|
query.IsLiked = true;
|
|
|
|
break;
|
|
|
|
case ItemFilter.Dislikes:
|
|
|
|
query.IsLiked = false;
|
|
|
|
break;
|
|
|
|
case ItemFilter.IsFavoriteOrLikes:
|
|
|
|
query.IsFavoriteOrLiked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return await _channelManager.GetLatestChannelItems(query, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|