From 342d454be47df95d2f79618e46d6f3d36a12df21 Mon Sep 17 00:00:00 2001 From: Violet Caulfield Date: Sun, 9 Feb 2025 14:13:48 -0600 Subject: [PATCH] adding playlist functionality and adding a lot more debugging --- api/mutations/functions/playlists.ts | 52 +++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/api/mutations/functions/playlists.ts b/api/mutations/functions/playlists.ts index 395066c0..ea3db963 100644 --- a/api/mutations/functions/playlists.ts +++ b/api/mutations/functions/playlists.ts @@ -1,8 +1,11 @@ -import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; +import { BaseItemDto, MediaType } from "@jellyfin/sdk/lib/generated-client/models"; import Client from "../../../api/client"; import { getPlaylistsApi } from "@jellyfin/sdk/lib/utils/api"; export async function addToPlaylist(track: BaseItemDto, playlist: BaseItemDto) { + + console.debug("Adding track to playlist"); + return getPlaylistsApi(Client.api!) .addItemToPlaylist({ ids: [ @@ -12,11 +15,58 @@ export async function addToPlaylist(track: BaseItemDto, playlist: BaseItemDto) { }) } +export async function removeFromPlaylist(track: BaseItemDto, playlist: BaseItemDto) { + console.debug("Removing track from playlist"); + + return getPlaylistsApi(Client.api!) + .removeItemFromPlaylist({ + playlistId: playlist.Id!, + entryIds: [ + track.Id! + ] + }); +} + export async function reorderPlaylist(playlistId: string, itemId: string, to: number) { + + console.debug(`Moving track to index ${to}`); + return getPlaylistsApi(Client.api!) .moveItem({ playlistId, itemId, newIndex: to }); +} + +export async function createPlaylist(name: string) { + console.debug("Creating new playlist"); + + return getPlaylistsApi(Client.api!) + .createPlaylist({ + name, + userId: Client.user!.id, + mediaType: MediaType.Audio + }); +} + +/** + * Updates a Jellyfin playlist with the provided options. + * + * Right now this just supports renaming playlists, but this will change + * when it comes time for collaborative playlists + * + * @param playlistId The Jellyfin ID of the playlist to update + * @returns + */ +export async function updatePlaylist(playlistId: string, name: string) { + console.debug("Updating playlist"); + + return getPlaylistsApi(Client.api!) + .updatePlaylist({ + playlistId, + updatePlaylistDto: { + Name: name + } + }); } \ No newline at end of file