2020-11-21 13:26:03 +00:00
|
|
|
using System;
|
2020-12-10 18:36:31 +00:00
|
|
|
using System.Collections.Generic;
|
2020-08-06 14:17:45 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-06-08 19:14:41 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
2021-01-20 23:24:15 +00:00
|
|
|
using Jellyfin.Api.Attributes;
|
2020-06-20 22:03:19 +00:00
|
|
|
using Jellyfin.Api.Extensions;
|
2023-02-17 22:16:08 +00:00
|
|
|
using Jellyfin.Api.Helpers;
|
2020-11-09 21:59:04 +00:00
|
|
|
using Jellyfin.Api.ModelBinders;
|
2020-06-08 19:14:41 +00:00
|
|
|
using Jellyfin.Api.Models.PlaylistDtos;
|
2023-05-13 18:44:31 +00:00
|
|
|
using Jellyfin.Data.Enums;
|
2024-01-17 15:51:39 +00:00
|
|
|
using Jellyfin.Extensions;
|
2020-06-08 19:14:41 +00:00
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Playlists;
|
|
|
|
using MediaBrowser.Model.Dto;
|
2020-10-09 23:52:39 +00:00
|
|
|
using MediaBrowser.Model.Entities;
|
2020-06-08 19:14:41 +00:00
|
|
|
using MediaBrowser.Model.Playlists;
|
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-12-10 18:36:31 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
namespace Jellyfin.Api.Controllers;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Playlists controller.
|
|
|
|
/// </summary>
|
2023-02-08 22:55:26 +00:00
|
|
|
[Authorize]
|
2023-01-31 11:18:10 +00:00
|
|
|
public class PlaylistsController : BaseJellyfinApiController
|
2020-06-08 19:14:41 +00:00
|
|
|
{
|
2023-01-31 11:18:10 +00:00
|
|
|
private readonly IPlaylistManager _playlistManager;
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
2020-06-08 19:14:41 +00:00
|
|
|
/// <summary>
|
2023-01-31 11:18:10 +00:00
|
|
|
/// Initializes a new instance of the <see cref="PlaylistsController"/> class.
|
2020-06-08 19:14:41 +00:00
|
|
|
/// </summary>
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
|
|
|
|
/// <param name="playlistManager">Instance of the <see cref="IPlaylistManager"/> interface.</param>
|
|
|
|
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
|
|
|
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
|
|
|
public PlaylistsController(
|
|
|
|
IDtoService dtoService,
|
|
|
|
IPlaylistManager playlistManager,
|
|
|
|
IUserManager userManager,
|
|
|
|
ILibraryManager libraryManager)
|
2020-06-08 19:14:41 +00:00
|
|
|
{
|
2023-01-31 11:18:10 +00:00
|
|
|
_dtoService = dtoService;
|
|
|
|
_playlistManager = playlistManager;
|
|
|
|
_userManager = userManager;
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
}
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new playlist.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// For backwards compatibility parameters can be sent via Query or Body, with Query having higher precedence.
|
|
|
|
/// Query parameters are obsolete.
|
|
|
|
/// </remarks>
|
|
|
|
/// <param name="name">The playlist name.</param>
|
|
|
|
/// <param name="ids">The item ids.</param>
|
|
|
|
/// <param name="userId">The user id.</param>
|
|
|
|
/// <param name="mediaType">The media type.</param>
|
|
|
|
/// <param name="createPlaylistRequest">The create playlist payload.</param>
|
2023-05-12 13:11:59 +00:00
|
|
|
/// <response code="200">Playlist created.</response>
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <returns>
|
|
|
|
/// A <see cref="Task" /> that represents the asynchronous operation to create a playlist.
|
|
|
|
/// The task result contains an <see cref="OkResult"/> indicating success.
|
|
|
|
/// </returns>
|
|
|
|
[HttpPost]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public async Task<ActionResult<PlaylistCreationResult>> CreatePlaylist(
|
|
|
|
[FromQuery, ParameterObsolete] string? name,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder)), ParameterObsolete] IReadOnlyList<Guid> ids,
|
|
|
|
[FromQuery, ParameterObsolete] Guid? userId,
|
2023-05-13 18:44:31 +00:00
|
|
|
[FromQuery, ParameterObsolete] MediaType? mediaType,
|
2023-01-31 11:18:10 +00:00
|
|
|
[FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] CreatePlaylistDto? createPlaylistRequest)
|
|
|
|
{
|
|
|
|
if (ids.Count == 0)
|
2020-06-08 19:14:41 +00:00
|
|
|
{
|
2023-01-31 11:18:10 +00:00
|
|
|
ids = createPlaylistRequest?.Ids ?? Array.Empty<Guid>();
|
2020-06-08 19:14:41 +00:00
|
|
|
}
|
|
|
|
|
2023-02-17 22:16:08 +00:00
|
|
|
userId ??= createPlaylistRequest?.UserId ?? default;
|
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2023-01-31 11:18:10 +00:00
|
|
|
var result = await _playlistManager.CreatePlaylist(new PlaylistCreationRequest
|
2020-06-08 19:14:41 +00:00
|
|
|
{
|
2023-01-31 11:18:10 +00:00
|
|
|
Name = name ?? createPlaylistRequest?.Name,
|
|
|
|
ItemIdList = ids,
|
2023-02-17 22:16:08 +00:00
|
|
|
UserId = userId.Value,
|
2024-03-26 15:13:07 +00:00
|
|
|
MediaType = mediaType ?? createPlaylistRequest?.MediaType,
|
2024-03-26 22:45:14 +00:00
|
|
|
Users = createPlaylistRequest?.Users.ToArray() ?? [],
|
|
|
|
Public = createPlaylistRequest?.Public
|
2023-01-31 11:18:10 +00:00
|
|
|
}).ConfigureAwait(false);
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
return result;
|
|
|
|
}
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2024-03-26 14:29:48 +00:00
|
|
|
/// <summary>
|
2024-04-01 18:43:05 +00:00
|
|
|
/// Updates a playlist.
|
2024-03-26 14:29:48 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="playlistId">The playlist id.</param>
|
2024-04-01 18:43:05 +00:00
|
|
|
/// <param name="updatePlaylistRequest">The <see cref="UpdatePlaylistDto"/> id.</param>
|
|
|
|
/// <response code="204">Playlist updated.</response>
|
2024-03-27 05:39:14 +00:00
|
|
|
/// <response code="401">Unauthorized access.</response>
|
|
|
|
/// <response code="404">Playlist not found.</response>
|
2024-03-26 14:29:48 +00:00
|
|
|
/// <returns>
|
2024-04-01 18:43:05 +00:00
|
|
|
/// A <see cref="Task" /> that represents the asynchronous operation to update a playlist.
|
|
|
|
/// The task result contains an <see cref="OkResult"/> indicating success.
|
2024-03-26 14:29:48 +00:00
|
|
|
/// </returns>
|
2024-04-01 18:43:05 +00:00
|
|
|
[HttpPost("{playlistId}")]
|
2024-03-26 14:29:48 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-03-27 05:39:14 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
2024-04-01 18:43:05 +00:00
|
|
|
public async Task<ActionResult> UpdatePlaylist(
|
|
|
|
[FromRoute, Required] Guid playlistId,
|
|
|
|
[FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Disallow)] UpdatePlaylistDto updatePlaylistRequest)
|
2024-03-26 14:29:48 +00:00
|
|
|
{
|
2024-04-01 18:43:05 +00:00
|
|
|
var callingUserId = User.GetUserId();
|
2024-03-26 14:29:48 +00:00
|
|
|
|
2024-04-02 06:08:36 +00:00
|
|
|
var playlist = _playlistManager.GetPlaylistForUser(playlistId, callingUserId);
|
2024-03-27 05:39:14 +00:00
|
|
|
if (playlist is null)
|
|
|
|
{
|
|
|
|
return NotFound("Playlist not found");
|
|
|
|
}
|
|
|
|
|
2024-04-01 18:43:05 +00:00
|
|
|
var isPermitted = playlist.OwnerUserId.Equals(callingUserId)
|
|
|
|
|| playlist.Shares.Any(s => s.CanEdit && s.UserId.Equals(callingUserId));
|
2024-03-26 14:29:48 +00:00
|
|
|
|
2024-04-01 18:43:05 +00:00
|
|
|
if (!isPermitted)
|
|
|
|
{
|
|
|
|
return Unauthorized("Unauthorized access");
|
|
|
|
}
|
|
|
|
|
|
|
|
await _playlistManager.UpdatePlaylist(new PlaylistUpdateRequest
|
|
|
|
{
|
|
|
|
UserId = callingUserId,
|
|
|
|
Id = playlistId,
|
|
|
|
Name = updatePlaylistRequest.Name,
|
|
|
|
Ids = updatePlaylistRequest.Ids,
|
|
|
|
Users = updatePlaylistRequest.Users,
|
|
|
|
Public = updatePlaylistRequest.Public
|
|
|
|
}).ConfigureAwait(false);
|
|
|
|
|
|
|
|
return NoContent();
|
2024-03-26 14:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-01 18:43:05 +00:00
|
|
|
/// Get a playlist's users.
|
2024-03-26 14:29:48 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="playlistId">The playlist id.</param>
|
2024-04-01 18:43:05 +00:00
|
|
|
/// <response code="200">Found shares.</response>
|
2024-03-27 05:39:14 +00:00
|
|
|
/// <response code="401">Unauthorized access.</response>
|
|
|
|
/// <response code="404">Playlist not found.</response>
|
2024-03-26 14:29:48 +00:00
|
|
|
/// <returns>
|
2024-04-01 18:43:05 +00:00
|
|
|
/// A list of <see cref="PlaylistUserPermissions"/> objects.
|
2024-03-26 14:29:48 +00:00
|
|
|
/// </returns>
|
2024-04-01 18:43:05 +00:00
|
|
|
[HttpGet("{playlistId}/User")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-03-27 05:39:14 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
2024-04-01 18:43:05 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
public ActionResult<IReadOnlyList<PlaylistUserPermissions>> GetPlaylistUsers(
|
2024-03-26 14:29:48 +00:00
|
|
|
[FromRoute, Required] Guid playlistId)
|
|
|
|
{
|
2024-04-01 18:43:05 +00:00
|
|
|
var userId = User.GetUserId();
|
2024-03-26 14:29:48 +00:00
|
|
|
|
2024-04-02 06:08:36 +00:00
|
|
|
var playlist = _playlistManager.GetPlaylistForUser(playlistId, userId);
|
2024-03-27 05:39:14 +00:00
|
|
|
if (playlist is null)
|
|
|
|
{
|
|
|
|
return NotFound("Playlist not found");
|
|
|
|
}
|
|
|
|
|
2024-04-01 18:43:05 +00:00
|
|
|
var isPermitted = playlist.OwnerUserId.Equals(userId)
|
|
|
|
|| playlist.Shares.Any(s => s.CanEdit && s.UserId.Equals(userId));
|
2024-03-26 14:29:48 +00:00
|
|
|
|
2024-04-01 18:43:05 +00:00
|
|
|
return isPermitted ? playlist.Shares.ToList() : Unauthorized("Unauthorized Access");
|
2024-03-26 14:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2024-03-27 05:39:14 +00:00
|
|
|
/// Modify a user to a playlist's users.
|
2024-03-26 14:29:48 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="playlistId">The playlist id.</param>
|
2024-03-26 22:45:14 +00:00
|
|
|
/// <param name="userId">The user id.</param>
|
2024-04-02 06:08:36 +00:00
|
|
|
/// <param name="updatePlaylistUserRequest">The <see cref="UpdatePlaylistUserDto"/>.</param>
|
2024-03-27 05:39:14 +00:00
|
|
|
/// <response code="204">User's permissions modified.</response>
|
|
|
|
/// <response code="401">Unauthorized access.</response>
|
|
|
|
/// <response code="404">Playlist not found.</response>
|
2024-03-26 14:29:48 +00:00
|
|
|
/// <returns>
|
2024-03-27 05:39:14 +00:00
|
|
|
/// A <see cref="Task" /> that represents the asynchronous operation to modify an user's playlist permissions.
|
2024-03-26 14:29:48 +00:00
|
|
|
/// The task result contains an <see cref="OkResult"/> indicating success.
|
|
|
|
/// </returns>
|
2024-03-26 22:45:14 +00:00
|
|
|
[HttpPost("{playlistId}/User/{userId}")]
|
2024-03-27 05:39:14 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
2024-04-02 06:08:36 +00:00
|
|
|
public async Task<ActionResult> UpdatePlaylistUser(
|
2024-03-26 14:29:48 +00:00
|
|
|
[FromRoute, Required] Guid playlistId,
|
2024-03-26 22:45:14 +00:00
|
|
|
[FromRoute, Required] Guid userId,
|
2024-04-02 06:08:36 +00:00
|
|
|
[FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] UpdatePlaylistUserDto updatePlaylistUserRequest)
|
2024-03-26 14:29:48 +00:00
|
|
|
{
|
2024-03-27 05:39:14 +00:00
|
|
|
var callingUserId = User.GetUserId();
|
2024-03-26 14:29:48 +00:00
|
|
|
|
2024-04-02 06:08:36 +00:00
|
|
|
var playlist = _playlistManager.GetPlaylistForUser(playlistId, callingUserId);
|
2024-03-27 05:39:14 +00:00
|
|
|
if (playlist is null)
|
|
|
|
{
|
|
|
|
return NotFound("Playlist not found");
|
|
|
|
}
|
|
|
|
|
2024-03-26 14:29:48 +00:00
|
|
|
var isPermitted = playlist.OwnerUserId.Equals(callingUserId)
|
2024-03-26 22:45:14 +00:00
|
|
|
|| playlist.Shares.Any(s => s.CanEdit && s.UserId.Equals(callingUserId));
|
2024-03-26 14:29:48 +00:00
|
|
|
|
|
|
|
if (!isPermitted)
|
|
|
|
{
|
|
|
|
return Unauthorized("Unauthorized access");
|
|
|
|
}
|
|
|
|
|
2024-04-02 06:08:36 +00:00
|
|
|
await _playlistManager.AddUserToShares(new PlaylistUserUpdateRequest
|
|
|
|
{
|
|
|
|
Id = playlistId,
|
|
|
|
UserId = userId,
|
|
|
|
CanEdit = updatePlaylistUserRequest.CanEdit
|
|
|
|
}).ConfigureAwait(false);
|
2024-03-26 14:29:48 +00:00
|
|
|
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Remove a user from a playlist's shares.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="playlistId">The playlist id.</param>
|
|
|
|
/// <param name="userId">The user id.</param>
|
2024-03-27 05:39:14 +00:00
|
|
|
/// <response code="204">User permissions removed from playlist.</response>
|
|
|
|
/// <response code="401">Unauthorized access.</response>
|
|
|
|
/// <response code="404">No playlist or user permissions found.</response>
|
2024-03-26 14:29:48 +00:00
|
|
|
/// <returns>
|
|
|
|
/// A <see cref="Task" /> that represents the asynchronous operation to delete a user from a playlist's shares.
|
|
|
|
/// The task result contains an <see cref="OkResult"/> indicating success.
|
|
|
|
/// </returns>
|
2024-03-26 22:45:14 +00:00
|
|
|
[HttpDelete("{playlistId}/User/{userId}")]
|
2024-03-27 05:39:14 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-03-26 22:45:14 +00:00
|
|
|
public async Task<ActionResult> RemoveUserFromPlaylist(
|
2024-03-26 14:29:48 +00:00
|
|
|
[FromRoute, Required] Guid playlistId,
|
2024-03-26 22:45:14 +00:00
|
|
|
[FromRoute, Required] Guid userId)
|
2024-03-26 14:29:48 +00:00
|
|
|
{
|
2024-03-27 05:39:14 +00:00
|
|
|
var callingUserId = User.GetUserId();
|
2024-03-26 14:29:48 +00:00
|
|
|
|
2024-04-02 06:08:36 +00:00
|
|
|
var playlist = _playlistManager.GetPlaylistForUser(playlistId, callingUserId);
|
2024-03-27 05:39:14 +00:00
|
|
|
if (playlist is null)
|
|
|
|
{
|
|
|
|
return NotFound("Playlist not found");
|
|
|
|
}
|
|
|
|
|
2024-03-26 14:29:48 +00:00
|
|
|
var isPermitted = playlist.OwnerUserId.Equals(callingUserId)
|
2024-03-26 22:45:14 +00:00
|
|
|
|| playlist.Shares.Any(s => s.CanEdit && s.UserId.Equals(callingUserId));
|
2024-03-26 14:29:48 +00:00
|
|
|
|
|
|
|
if (!isPermitted)
|
|
|
|
{
|
|
|
|
return Unauthorized("Unauthorized access");
|
|
|
|
}
|
|
|
|
|
2024-03-26 22:45:14 +00:00
|
|
|
var share = playlist.Shares.FirstOrDefault(s => s.UserId.Equals(userId));
|
2024-03-26 14:29:48 +00:00
|
|
|
if (share is null)
|
|
|
|
{
|
2024-03-27 05:39:14 +00:00
|
|
|
return NotFound("User permissions not found");
|
2024-03-26 14:29:48 +00:00
|
|
|
}
|
|
|
|
|
2024-04-02 06:08:36 +00:00
|
|
|
await _playlistManager.RemoveUserFromShares(playlistId, callingUserId, share).ConfigureAwait(false);
|
2024-03-26 14:29:48 +00:00
|
|
|
|
|
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Adds items to a playlist.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="playlistId">The playlist id.</param>
|
|
|
|
/// <param name="ids">Item id, comma delimited.</param>
|
|
|
|
/// <param name="userId">The userId.</param>
|
|
|
|
/// <response code="204">Items added to playlist.</response>
|
|
|
|
/// <returns>An <see cref="NoContentResult"/> on success.</returns>
|
|
|
|
[HttpPost("{playlistId}/Items")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2024-04-02 06:08:36 +00:00
|
|
|
public async Task<ActionResult> AddItemToPlaylist(
|
2023-01-31 11:18:10 +00:00
|
|
|
[FromRoute, Required] Guid playlistId,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] ids,
|
|
|
|
[FromQuery] Guid? userId)
|
|
|
|
{
|
2023-02-17 22:16:08 +00:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2024-04-02 06:08:36 +00:00
|
|
|
await _playlistManager.AddItemToPlaylistAsync(playlistId, ids, userId.Value).ConfigureAwait(false);
|
2023-01-31 11:18:10 +00:00
|
|
|
return NoContent();
|
|
|
|
}
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Moves a playlist item.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="playlistId">The playlist id.</param>
|
|
|
|
/// <param name="itemId">The item id.</param>
|
|
|
|
/// <param name="newIndex">The new index.</param>
|
|
|
|
/// <response code="204">Item moved to new index.</response>
|
|
|
|
/// <returns>An <see cref="NoContentResult"/> on success.</returns>
|
|
|
|
[HttpPost("{playlistId}/Items/{itemId}/Move/{newIndex}")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
public async Task<ActionResult> MoveItem(
|
|
|
|
[FromRoute, Required] string playlistId,
|
|
|
|
[FromRoute, Required] string itemId,
|
|
|
|
[FromRoute, Required] int newIndex)
|
|
|
|
{
|
|
|
|
await _playlistManager.MoveItemAsync(playlistId, itemId, newIndex).ConfigureAwait(false);
|
|
|
|
return NoContent();
|
|
|
|
}
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Removes items from a playlist.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="playlistId">The playlist id.</param>
|
|
|
|
/// <param name="entryIds">The item ids, comma delimited.</param>
|
|
|
|
/// <response code="204">Items removed.</response>
|
|
|
|
/// <returns>An <see cref="NoContentResult"/> on success.</returns>
|
|
|
|
[HttpDelete("{playlistId}/Items")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2024-04-02 06:08:36 +00:00
|
|
|
public async Task<ActionResult> RemoveItemFromPlaylist(
|
2023-01-31 11:18:10 +00:00
|
|
|
[FromRoute, Required] string playlistId,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] entryIds)
|
|
|
|
{
|
2024-04-02 06:08:36 +00:00
|
|
|
await _playlistManager.RemoveItemFromPlaylistAsync(playlistId, entryIds).ConfigureAwait(false);
|
2023-01-31 11:18:10 +00:00
|
|
|
return NoContent();
|
|
|
|
}
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the original items of a playlist.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="playlistId">The playlist id.</param>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <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="fields">Optional. Specify additional fields of information to return in the output.</param>
|
|
|
|
/// <param name="enableImages">Optional. Include image information in output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. Include user data.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <response code="200">Original playlist returned.</response>
|
|
|
|
/// <response code="404">Playlist not found.</response>
|
|
|
|
/// <returns>The original playlist items.</returns>
|
|
|
|
[HttpGet("{playlistId}/Items")]
|
2023-05-12 13:11:59 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-01-31 11:18:10 +00:00
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetPlaylistItems(
|
|
|
|
[FromRoute, Required] Guid playlistId,
|
2024-02-17 13:29:34 +00:00
|
|
|
[FromQuery] Guid? userId,
|
2023-01-31 11:18:10 +00:00
|
|
|
[FromQuery] int? startIndex,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
|
|
|
{
|
2024-02-17 13:29:34 +00:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2023-01-31 11:18:10 +00:00
|
|
|
var playlist = (Playlist)_libraryManager.GetItemById(playlistId);
|
|
|
|
if (playlist is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2024-02-17 13:29:34 +00:00
|
|
|
var user = userId.IsNullOrEmpty()
|
2023-01-31 11:18:10 +00:00
|
|
|
? null
|
2024-02-17 13:29:34 +00:00
|
|
|
: _userManager.GetUserById(userId.Value);
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
var items = playlist.GetManageableItems().ToArray();
|
|
|
|
var count = items.Length;
|
|
|
|
if (startIndex.HasValue)
|
|
|
|
{
|
|
|
|
items = items.Skip(startIndex.Value).ToArray();
|
|
|
|
}
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
if (limit.HasValue)
|
|
|
|
{
|
|
|
|
items = items.Take(limit.Value).ToArray();
|
|
|
|
}
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
var dtoOptions = new DtoOptions { Fields = fields }
|
|
|
|
.AddClientFields(User)
|
|
|
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
2020-06-08 19:14:41 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
var dtos = _dtoService.GetBaseItemDtos(items.Select(i => i.Item2).ToList(), dtoOptions, user);
|
|
|
|
for (int index = 0; index < dtos.Count; index++)
|
|
|
|
{
|
|
|
|
dtos[index].PlaylistItemId = items[index].Item1.Id;
|
2020-06-08 19:14:41 +00:00
|
|
|
}
|
2023-01-31 11:18:10 +00:00
|
|
|
|
|
|
|
var result = new QueryResult<BaseItemDto>(
|
|
|
|
startIndex,
|
|
|
|
count,
|
|
|
|
dtos);
|
|
|
|
|
|
|
|
return result;
|
2020-06-08 19:14:41 +00:00
|
|
|
}
|
|
|
|
}
|