diff --git a/Jellyfin.Api/Controllers/PlaylistsController.cs b/Jellyfin.Api/Controllers/PlaylistsController.cs
index 63d6e1cc30..e6f23b1364 100644
--- a/Jellyfin.Api/Controllers/PlaylistsController.cs
+++ b/Jellyfin.Api/Controllers/PlaylistsController.cs
@@ -149,6 +149,37 @@ public class PlaylistsController : BaseJellyfinApiController
return NoContent();
}
+ ///
+ /// Get a playlist.
+ ///
+ /// The playlist id.
+ /// The playlist.
+ /// Playlist not found.
+ ///
+ /// A objects.
+ ///
+ [HttpGet("{playlistId}")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
+ public ActionResult GetPlaylist(
+ [FromRoute, Required] Guid playlistId)
+ {
+ var userId = User.GetUserId();
+
+ var playlist = _playlistManager.GetPlaylistForUser(playlistId, userId);
+ if (playlist is null)
+ {
+ return NotFound("Playlist not found");
+ }
+
+ return new PlaylistDto()
+ {
+ Shares = playlist.Shares,
+ OpenAccess = playlist.OpenAccess,
+ ItemIds = playlist.GetManageableItems().Select(t => t.Item2.Id).ToList()
+ };
+ }
+
///
/// Get a playlist's users.
///
@@ -467,32 +498,23 @@ public class PlaylistsController : BaseJellyfinApiController
[FromQuery] int? imageTypeLimit,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
{
- userId = RequestHelpers.GetUserId(User, userId);
- var playlist = _playlistManager.GetPlaylistForUser(playlistId, userId.Value);
+ var callingUserId = userId ?? User.GetUserId();
+ var playlist = _playlistManager.GetPlaylistForUser(playlistId, callingUserId);
if (playlist is null)
{
return NotFound("Playlist not found");
}
var isPermitted = playlist.OpenAccess
- || playlist.OwnerUserId.Equals(userId.Value)
- || playlist.Shares.Any(s => s.UserId.Equals(userId.Value));
+ || playlist.OwnerUserId.Equals(callingUserId)
+ || playlist.Shares.Any(s => s.UserId.Equals(callingUserId));
if (!isPermitted)
{
return Forbid();
}
- var user = userId.IsNullOrEmpty()
- ? null
- : _userManager.GetUserById(userId.Value);
- var item = _libraryManager.GetItemById(playlistId, user);
- if (item is null)
- {
- return NotFound();
- }
-
- var items = item.GetManageableItems().ToArray();
+ var items = playlist.GetManageableItems().ToArray();
var count = items.Length;
if (startIndex.HasValue)
{
@@ -507,7 +529,7 @@ public class PlaylistsController : BaseJellyfinApiController
var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(User)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
-
+ var user = _userManager.GetUserById(callingUserId);
var dtos = _dtoService.GetBaseItemDtos(items.Select(i => i.Item2).ToList(), dtoOptions, user);
for (int index = 0; index < dtos.Count; index++)
{
diff --git a/MediaBrowser.Model/Dto/PlaylistDto.cs b/MediaBrowser.Model/Dto/PlaylistDto.cs
new file mode 100644
index 0000000000..d4de75a784
--- /dev/null
+++ b/MediaBrowser.Model/Dto/PlaylistDto.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using MediaBrowser.Model.Entities;
+
+namespace MediaBrowser.Model.Dto;
+
+///
+/// DTO for playlists.
+///
+public class PlaylistDto
+{
+ ///
+ /// Gets or sets a value indicating whether the playlist is publicly readable.
+ ///
+ public bool OpenAccess { get; set; }
+
+ ///
+ /// Gets or sets the share permissions.
+ ///
+ public required IReadOnlyList Shares { get; set; }
+
+ ///
+ /// Gets or sets the item ids.
+ ///
+ public required IReadOnlyList ItemIds { get; set; }
+}