mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-29 14:47:21 +02:00
Auto play podcast episode & check for local copy
This commit is contained in:
@@ -39,6 +39,7 @@ export default {
|
|||||||
shelves: [],
|
shelves: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
isFirstNetworkConnection: true,
|
isFirstNetworkConnection: true,
|
||||||
|
isFirstAutoOpenPlayer: true,
|
||||||
lastServerFetch: 0,
|
lastServerFetch: 0,
|
||||||
lastServerFetchLibraryId: null,
|
lastServerFetchLibraryId: null,
|
||||||
lastLocalFetch: 0,
|
lastLocalFetch: 0,
|
||||||
@@ -247,14 +248,7 @@ export default {
|
|||||||
return cat
|
return cat
|
||||||
})
|
})
|
||||||
|
|
||||||
// If we don't already have a player open
|
this.openMediaPlayerWithMostRecentListening()
|
||||||
// Try opening the first book from continue-listening without playing it
|
|
||||||
if (!this.$store.state.playerLibraryItemId) {
|
|
||||||
const lastListening = categories.filter((cat) => cat.id === 'continue-listening')[0]?.entities?.[0]?.id
|
|
||||||
if (lastListening) {
|
|
||||||
this.$eventBus.$emit('play-item', { libraryItemId: lastListening, paused: true })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only add the local shelf with the same media type
|
// Only add the local shelf with the same media type
|
||||||
const localShelves = localCategories.filter((cat) => cat.type === this.currentLibraryMediaType && !cat.localOnly)
|
const localShelves = localCategories.filter((cat) => cat.type === this.currentLibraryMediaType && !cat.localOnly)
|
||||||
@@ -270,6 +264,40 @@ export default {
|
|||||||
|
|
||||||
this.loading = false
|
this.loading = false
|
||||||
},
|
},
|
||||||
|
openMediaPlayerWithMostRecentListening() {
|
||||||
|
// If we don't already have a player open
|
||||||
|
// Try opening the first book from continue-listening without playing it
|
||||||
|
if (this.$store.state.playerLibraryItemId || !this.isFirstAutoOpenPlayer) return
|
||||||
|
this.isFirstAutoOpenPlayer = false // Only run this once, not on every library change
|
||||||
|
|
||||||
|
const continueListeningShelf = this.shelves.find((cat) => cat.id === 'continue-listening')
|
||||||
|
const mostRecentEntity = continueListeningShelf?.entities?.[0]
|
||||||
|
if (mostRecentEntity) {
|
||||||
|
const playObject = {
|
||||||
|
libraryItemId: mostRecentEntity.id,
|
||||||
|
episodeId: mostRecentEntity.recentEpisode?.id || null,
|
||||||
|
paused: true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there is a local copy
|
||||||
|
if (mostRecentEntity.localLibraryItem) {
|
||||||
|
if (mostRecentEntity.recentEpisode) {
|
||||||
|
// Check if the podcast episode has a local copy
|
||||||
|
const localEpisode = mostRecentEntity.localLibraryItem.media.episodes.find((ep) => ep.serverEpisodeId === mostRecentEntity.recentEpisode.id)
|
||||||
|
if (localEpisode) {
|
||||||
|
playObject.libraryItemId = mostRecentEntity.localLibraryItem.id
|
||||||
|
playObject.episodeId = localEpisode.id
|
||||||
|
playObject.serverLibraryItemId = mostRecentEntity.id
|
||||||
|
playObject.serverEpisodeId = mostRecentEntity.recentEpisode.id
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
playObject.libraryItemId = mostRecentEntity.localLibraryItem.id
|
||||||
|
playObject.serverLibraryItemId = mostRecentEntity.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.$eventBus.$emit('play-item', playObject)
|
||||||
|
}
|
||||||
|
},
|
||||||
libraryChanged() {
|
libraryChanged() {
|
||||||
if (this.currentLibraryId) {
|
if (this.currentLibraryId) {
|
||||||
console.log(`[categories] libraryChanged so fetching categories`)
|
console.log(`[categories] libraryChanged so fetching categories`)
|
||||||
|
|||||||
Reference in New Issue
Block a user