From d799d503911c8549f0384bde01fc942c91323184 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 10 Nov 2024 00:29:24 +0100 Subject: [PATCH] [Jellyfin UI] Implemented add to/remove from playlist. Closes: #414 --- .../components/panels/Media/PlaylistAdder.vue | 146 ++++++++++++++---- .../panels/Media/Providers/Jellyfin.vue | 1 + .../Providers/Jellyfin/views/Media/Index.vue | 4 +- .../Providers/Jellyfin/views/Music/Index.vue | 45 ++++-- .../panels/Media/Providers/YouTube.vue | 2 +- 5 files changed, 153 insertions(+), 45 deletions(-) diff --git a/platypush/backend/http/webapp/src/components/panels/Media/PlaylistAdder.vue b/platypush/backend/http/webapp/src/components/panels/Media/PlaylistAdder.vue index 1bf1a25d24..bd9b3016c7 100644 --- a/platypush/backend/http/webapp/src/components/panels/Media/PlaylistAdder.vue +++ b/platypush/backend/http/webapp/src/components/panels/Media/PlaylistAdder.vue @@ -5,19 +5,30 @@ Playlist name -
-
- +
+
+
+ +
+ +
+ +
-
- +
+
+ +
@@ -41,13 +52,53 @@ export default { data() { return { + filter: '', loading: false, playlists: [], showNewPlaylist: false, } }, + computed: { + pluginName() { + switch (this.item.type) { + case 'youtube': + return 'youtube' + + case 'jellyfin': + return 'media.jellyfin' + + default: + return null + } + }, + + sortedPlaylists() { + return this.playlists + .filter((playlist) => playlist.name.toLowerCase().includes(this.filter.toLowerCase())) + .sort((a, b) => a.name.localeCompare(b.name)) + }, + }, + methods: { + checkPlugin() { + if (!this.pluginName) { + this.notify({ + title: 'Unsupported item type', + text: `Item type ${this.item.type} does not support playlists`, + warning: true, + image: { + icon: 'exclamation-triangle', + } + }) + + console.warn(`Unsupported item type: ${this.item.type}`) + return false + } + + return true + }, + async createPlaylist(name) { name = name?.trim() if (!name?.length) @@ -56,23 +107,11 @@ export default { this.loading = true try { - const playlist = await this.request('youtube.create_playlist', { + const playlist = await this.request(`${this.pluginName}.create_playlist`, { name: name, }) - await this.request('youtube.add_to_playlist', { - playlist_id: playlist.id, - video_id: this.item.id || this.item.url, - }) - - this.$emit('done') - this.notify({ - text: 'Playlist created and video added', - image: { - icon: 'check', - } - }) - + await this.addToPlaylist(playlist.id) } finally { this.loading = false this.showNewPlaylist = false @@ -80,26 +119,30 @@ export default { }, async refreshPlaylists() { - this.loading = true + if (!this.checkPlugin()) + return + this.loading = true try { - this.playlists = await this.request('youtube.get_playlists') + this.playlists = await this.request(`${this.pluginName}.get_playlists`) } finally { this.loading = false } }, async addToPlaylist(playlistId) { - this.loading = true + if (!this.checkPlugin()) + return + this.loading = true try { - await this.request('youtube.add_to_playlist', { + await this.request(`${this.pluginName}.add_to_playlist`, { playlist_id: playlistId, - video_id: this.item.id || this.item.url, + item_ids: [this.item.id || this.item.url], }) this.notify({ - text: 'Video added to playlist', + text: 'Item added to playlist', image: { icon: 'check', } @@ -112,6 +155,15 @@ export default { }, }, + watch: { + loading() { + if (this.loading) + return + + this.$nextTick(() => this.$refs.playlistFilter.focus()) + }, + }, + mounted() { this.refreshPlaylists() }, @@ -119,19 +171,47 @@ export default {