From c8b5cefeb5f09434ea864b8622b6ad38039e337a Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 9 Jun 2023 17:05:29 -0500 Subject: [PATCH] Fix:Playlist items playing from server and not using local copy #734 --- .../audiobookshelf/app/data/DeviceClasses.kt | 1 - .../app/player/PlayerNotificationService.kt | 2 +- components/cards/LazyBookCard.vue | 1 + components/tables/playlist/ItemTableRow.vue | 26 +++++++++++--- pages/playlist/_id.vue | 35 ++++++++++++++++--- 5 files changed, 55 insertions(+), 10 deletions(-) diff --git a/android/app/src/main/java/com/audiobookshelf/app/data/DeviceClasses.kt b/android/app/src/main/java/com/audiobookshelf/app/data/DeviceClasses.kt index 2fd133be..73add537 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/data/DeviceClasses.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/data/DeviceClasses.kt @@ -91,7 +91,6 @@ data class DeviceInfo( var deviceId:String, var manufacturer:String, var model:String, - var brand:String, var sdkVersion:Int, var clientVersion: String ) diff --git a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt index df796a1f..197ca712 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt @@ -922,7 +922,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { appVersion: 0.9.46-beta */ val deviceId = Settings.Secure.getString(ctx.contentResolver, Settings.Secure.ANDROID_ID) - return DeviceInfo(deviceId, Build.MANUFACTURER, Build.MODEL, Build.BRAND, Build.VERSION.SDK_INT, BuildConfig.VERSION_NAME) + return DeviceInfo(deviceId, Build.MANUFACTURER, Build.MODEL, Build.VERSION.SDK_INT, BuildConfig.VERSION_NAME) } private val deviceSettings get() = DeviceManager.deviceData.deviceSettings ?: DeviceSettings.default() diff --git a/components/cards/LazyBookCard.vue b/components/cards/LazyBookCard.vue index eb25e831..c0118a3e 100644 --- a/components/cards/LazyBookCard.vue +++ b/components/cards/LazyBookCard.vue @@ -47,6 +47,7 @@
+
{{ isLocalOnly ? 'task' : 'download_done' }}
diff --git a/components/tables/playlist/ItemTableRow.vue b/components/tables/playlist/ItemTableRow.vue index 7bcde807..8339db39 100644 --- a/components/tables/playlist/ItemTableRow.vue +++ b/components/tables/playlist/ItemTableRow.vue @@ -6,9 +6,9 @@
-

{{ itemTitle }}

-

{{ bookAuthorName }}

-

{{ itemDuration }}

+

{{ itemTitle }} download_done

+

{{ authorName }}

+

{{ itemDuration }}

@@ -39,11 +39,17 @@ export default { libraryItem() { return this.item.libraryItem || {} }, + localLibraryItem() { + return this.item.localLibraryItem + }, episode() { return this.item.episode }, episodeId() { - return this.episode ? this.episode.id : null + return this.episode?.id || null + }, + localEpisode() { + return this.item.localEpisode }, media() { return this.libraryItem.media || {} @@ -66,6 +72,10 @@ export default { bookAuthorName() { return this.bookAuthors.map((au) => au.name).join(', ') }, + authorName() { + if (this.episode) return this.mediaMetadata.author + return this.bookAuthorName + }, itemDuration() { if (this.episode) return this.$elapsedPretty(this.episode.duration) return this.$elapsedPretty(this.media.duration) @@ -92,6 +102,7 @@ export default { return !this.isMissing && !this.isInvalid && (this.tracks.length || this.episode) }, isStreaming() { + if (this.localLibraryItem && this.$store.getters['getIsEpisodeStreaming'](this.localLibraryItem.id, this.localEpisode?.id)) return true return this.$store.getters['getIsEpisodeStreaming'](this.libraryItem.id, this.episodeId) }, streamIsPlaying() { @@ -103,6 +114,13 @@ export default { await this.$hapticsImpact() if (this.streamIsPlaying) { this.$eventBus.$emit('pause-item') + } else if (this.localLibraryItem) { + this.$eventBus.$emit('play-item', { + libraryItemId: this.localLibraryItem.id, + episodeId: this.localEpisode?.id, + serverLibraryItemId: this.libraryItem.id, + serverEpisodeId: this.episodeId + }) } else { this.$eventBus.$emit('play-item', { libraryItemId: this.libraryItem.id, diff --git a/pages/playlist/_id.vue b/pages/playlist/_id.vue index ff764b90..0acc4823 100644 --- a/pages/playlist/_id.vue +++ b/pages/playlist/_id.vue @@ -44,6 +44,26 @@ export default { return redirect('/bookshelf/playlists') } + // Lookup matching local items & episodes and attach to playlist items + if (playlist.items.length) { + const localLibraryItems = (await app.$db.getLocalLibraryItems(playlist.items[0].libraryItem.mediaType)) || [] + if (localLibraryItems.length) { + playlist.items.forEach((playlistItem) => { + const matchingLocalLibraryItem = localLibraryItems.find((lli) => lli.libraryItemId === playlistItem.libraryItemId) + if (!matchingLocalLibraryItem) return + if (playlistItem.episode) { + const matchingLocalEpisode = matchingLocalLibraryItem.media.episodes?.find((lep) => lep.serverEpisodeId === playlistItem.episodeId) + if (matchingLocalEpisode) { + playlistItem.localLibraryItem = matchingLocalLibraryItem + playlistItem.localEpisode = matchingLocalEpisode + } + } else { + playlistItem.localLibraryItem = matchingLocalLibraryItem + } + }) + } + } + return { playlist } @@ -73,7 +93,10 @@ export default { }) }, streaming() { - return !!this.playableItems.find((i) => this.$store.getters['getIsMediaStreaming'](i.libraryItemId, i.episodeId)) + return !!this.playableItems.find((i) => { + if (i.localLibraryItem && this.$store.getters['getIsMediaStreaming'](i.localLibraryItem.id, i.localEpisode?.id)) return true + return this.$store.getters['getIsMediaStreaming'](i.libraryItemId, i.episodeId) + }) }, showPlayButton() { return this.playableItems.length @@ -82,11 +105,15 @@ export default { methods: { clickPlay() { const nextItem = this.playableItems.find((i) => { - var prog = this.$store.getters['user/getUserMediaProgress'](i.libraryItemId, i.episodeId) - return !prog || !prog.isFinished + const prog = this.$store.getters['user/getUserMediaProgress'](i.libraryItemId, i.episodeId) + return !prog?.isFinished }) if (nextItem) { - this.$eventBus.$emit('play-item', { libraryItemId: nextItem.libraryItemId, episodeId: nextItem.episodeId }) + if (nextItem.localLibraryItem) { + this.$eventBus.$emit('play-item', { libraryItemId: nextItem.localLibraryItem.id, episodeId: nextItem.localEpisode?.id, serverLibraryItemId: nextItem.libraryItemId, serverEpisodeId: nextItem.episodeId }) + } else { + this.$eventBus.$emit('play-item', { libraryItemId: nextItem.libraryItemId, episodeId: nextItem.episodeId }) + } } } },