mirror of
https://github.com/Jellify-Music/App.git
synced 2026-01-07 03:20:19 -06:00
adding playlist functionality and adding a lot more debugging
This commit is contained in:
@@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user