-
+
+
-
-
+
+
+
+
@@ -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 {