mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-28 08:01:19 +01:00
Fix player content url, update user progress object include media entity id, update reset progress route
This commit is contained in:
parent
3d2bbc7719
commit
6a06ba4327
@ -259,7 +259,6 @@ export default {
|
|||||||
this.$store.commit('users/updateUser', user)
|
this.$store.commit('users/updateUser', user)
|
||||||
},
|
},
|
||||||
userItemProgressUpdate(payload) {
|
userItemProgressUpdate(payload) {
|
||||||
console.log('User item progress update', payload)
|
|
||||||
this.$store.commit('user/updateItemProgress', payload)
|
this.$store.commit('user/updateItemProgress', payload)
|
||||||
},
|
},
|
||||||
collectionAdded(collection) {
|
collectionAdded(collection) {
|
||||||
|
@ -117,7 +117,6 @@ export default {
|
|||||||
var errorMsg = err.response ? err.response.data || 'Unknown Error' : 'Unknown Error'
|
var errorMsg = err.response ? err.response.data || 'Unknown Error' : 'Unknown Error'
|
||||||
this.$toast.error(`Failed to get library stats: ${errorMsg}`)
|
this.$toast.error(`Failed to get library stats: ${errorMsg}`)
|
||||||
})
|
})
|
||||||
console.log('lib stats', this.libraryStats)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
</h1>
|
</h1>
|
||||||
<p v-if="subtitle" class="sm:ml-4 text-gray-400 text-xl md:text-2xl">{{ subtitle }}</p>
|
<p v-if="subtitle" class="sm:ml-4 text-gray-400 text-xl md:text-2xl">{{ subtitle }}</p>
|
||||||
</div>
|
</div>
|
||||||
<!-- <p v-if="subtitle" class="ml-4 text-gray-400 text-2xl block sm:hidden">{{ subtitle }}</p> -->
|
|
||||||
|
|
||||||
<p v-if="authorsList.length" class="mb-2 mt-0.5 text-gray-200 text-lg md:text-xl">
|
<p v-if="authorsList.length" class="mb-2 mt-0.5 text-gray-200 text-lg md:text-xl">
|
||||||
by <nuxt-link v-for="(author, index) in authorsList" :key="index" :to="`/library/${libraryId}/bookshelf?filter=authors.${$encode(author)}`" class="hover:underline">{{ author }}<span v-if="index < authorsList.length - 1">, </span></nuxt-link>
|
by <nuxt-link v-for="(author, index) in authorsList" :key="index" :to="`/library/${libraryId}/bookshelf?filter=authors.${$encode(author)}`" class="hover:underline">{{ author }}<span v-if="index < authorsList.length - 1">, </span></nuxt-link>
|
||||||
@ -69,7 +68,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="tracks.length" class="flex py-0.5">
|
<div v-if="audiobooks.length" class="flex py-0.5">
|
||||||
<div class="w-32">
|
<div class="w-32">
|
||||||
<span class="text-white text-opacity-60 uppercase text-sm">Duration</span>
|
<span class="text-white text-opacity-60 uppercase text-sm">Duration</span>
|
||||||
</div>
|
</div>
|
||||||
@ -77,7 +76,7 @@
|
|||||||
{{ durationPretty }}
|
{{ durationPretty }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="tracks.length" class="flex py-0.5">
|
<div v-if="audiobooks.length" class="flex py-0.5">
|
||||||
<div class="w-32">
|
<div class="w-32">
|
||||||
<span class="text-white text-opacity-60 uppercase text-sm">Size</span>
|
<span class="text-white text-opacity-60 uppercase text-sm">Size</span>
|
||||||
</div>
|
</div>
|
||||||
@ -220,6 +219,10 @@ export default {
|
|||||||
audiobooks() {
|
audiobooks() {
|
||||||
return this.media.audiobooks || []
|
return this.media.audiobooks || []
|
||||||
},
|
},
|
||||||
|
defaultAudiobook() {
|
||||||
|
if (!this.audiobooks.length) return null
|
||||||
|
return this.audiobooks[0]
|
||||||
|
},
|
||||||
title() {
|
title() {
|
||||||
return this.mediaMetadata.title || 'No Title'
|
return this.mediaMetadata.title || 'No Title'
|
||||||
},
|
},
|
||||||
@ -258,33 +261,28 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
durationPretty() {
|
durationPretty() {
|
||||||
return this.$elapsedPretty(this.media.duration)
|
if (!this.defaultAudiobook) return 'N/A'
|
||||||
|
return this.$elapsedPretty(this.defaultAudiobook.duration)
|
||||||
},
|
},
|
||||||
duration() {
|
duration() {
|
||||||
return this.media.duration
|
if (!this.defaultAudiobook) return 0
|
||||||
|
return this.defaultAudiobook.duration
|
||||||
},
|
},
|
||||||
sizePretty() {
|
sizePretty() {
|
||||||
return this.$bytesPretty(this.media.size)
|
if (!this.defaultAudiobook) return 'N/A'
|
||||||
|
return this.$bytesPretty(this.defaultAudiobook.size)
|
||||||
},
|
},
|
||||||
libraryFiles() {
|
libraryFiles() {
|
||||||
return this.libraryItem.libraryFiles || []
|
return this.libraryItem.libraryFiles || []
|
||||||
},
|
},
|
||||||
otherAudioFiles() {
|
audiobooks() {
|
||||||
return this.audioFiles.filter((af) => {
|
return this.media.audiobooks || []
|
||||||
return !this.tracks.find((t) => t.path === af.path)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
tracks() {
|
|
||||||
return this.media.tracks || []
|
|
||||||
},
|
|
||||||
audioFiles() {
|
|
||||||
return this.media.audioFiles || []
|
|
||||||
},
|
},
|
||||||
ebooks() {
|
ebooks() {
|
||||||
return this.media.ebooks || []
|
return this.media.ebooks || []
|
||||||
},
|
},
|
||||||
showExperimentalReadAlert() {
|
showExperimentalReadAlert() {
|
||||||
return !this.tracks.length && this.ebooks.length && !this.showExperimentalFeatures
|
return !this.audiobooks.length && this.ebooks.length && !this.showExperimentalFeatures
|
||||||
},
|
},
|
||||||
description() {
|
description() {
|
||||||
return this.mediaMetadata.description || ''
|
return this.mediaMetadata.description || ''
|
||||||
@ -292,14 +290,13 @@ export default {
|
|||||||
userItemProgress() {
|
userItemProgress() {
|
||||||
return this.$store.getters['user/getUserLibraryItemProgress'](this.libraryItemId)
|
return this.$store.getters['user/getUserLibraryItemProgress'](this.libraryItemId)
|
||||||
},
|
},
|
||||||
userCurrentTime() {
|
|
||||||
return this.userItemProgress ? this.userItemProgress.currentTime : 0
|
|
||||||
},
|
|
||||||
userIsFinished() {
|
userIsFinished() {
|
||||||
return this.userItemProgress ? !!this.userItemProgress.isFinished : false
|
return this.userItemProgress ? !!this.userItemProgress.isFinished : false
|
||||||
},
|
},
|
||||||
userTimeRemaining() {
|
userTimeRemaining() {
|
||||||
return this.duration - this.userCurrentTime
|
if (!this.userItemProgress) return 0
|
||||||
|
var duration = this.userItemProgress.duration || this.duration
|
||||||
|
return duration - this.userItemProgress.currentTime
|
||||||
},
|
},
|
||||||
progressPercent() {
|
progressPercent() {
|
||||||
return this.userItemProgress ? Math.max(Math.min(1, this.userItemProgress.progress), 0) : 0
|
return this.userItemProgress ? Math.max(Math.min(1, this.userItemProgress.progress), 0) : 0
|
||||||
|
@ -26,6 +26,6 @@ export default class AudioTrack {
|
|||||||
return `${process.env.serverUrl}${this.contentUrl}?token=${this.userToken}`
|
return `${process.env.serverUrl}${this.contentUrl}?token=${this.userToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.contentUrl + '?token=${this.userToken}'
|
return this.contentUrl + `?token=${this.userToken}`
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,6 +11,7 @@ export default class PlayerHandler {
|
|||||||
this.playerState = 'IDLE'
|
this.playerState = 'IDLE'
|
||||||
this.isHlsTranscode = false
|
this.isHlsTranscode = false
|
||||||
this.currentSessionId = null
|
this.currentSessionId = null
|
||||||
|
this.mediaEntityId = null
|
||||||
this.startTime = 0
|
this.startTime = 0
|
||||||
|
|
||||||
this.lastSyncTime = 0
|
this.lastSyncTime = 0
|
||||||
@ -107,7 +108,7 @@ export default class PlayerHandler {
|
|||||||
this.stopPlayInterval()
|
this.stopPlayInterval()
|
||||||
}
|
}
|
||||||
if (this.playerState === 'LOADED' || this.playerState === 'PLAYING') {
|
if (this.playerState === 'LOADED' || this.playerState === 'PLAYING') {
|
||||||
this.ctx.setDuration(this.player.getDuration())
|
this.ctx.setDuration(this.getDuration())
|
||||||
}
|
}
|
||||||
if (this.playerState !== 'LOADING') {
|
if (this.playerState !== 'LOADING') {
|
||||||
this.ctx.setCurrentTime(this.player.getCurrentTime())
|
this.ctx.setCurrentTime(this.player.getCurrentTime())
|
||||||
@ -149,6 +150,7 @@ export default class PlayerHandler {
|
|||||||
prepareSession(session) {
|
prepareSession(session) {
|
||||||
this.startTime = session.currentTime
|
this.startTime = session.currentTime
|
||||||
this.currentSessionId = session.id
|
this.currentSessionId = session.id
|
||||||
|
this.mediaEntityId = session.mediaEntityId
|
||||||
|
|
||||||
console.log('[PlayerHandler] Preparing Session', session)
|
console.log('[PlayerHandler] Preparing Session', session)
|
||||||
var audioTracks = session.audioTracks.map(at => new AudioTrack(at, this.userToken))
|
var audioTracks = session.audioTracks.map(at => new AudioTrack(at, this.userToken))
|
||||||
@ -207,7 +209,9 @@ export default class PlayerHandler {
|
|||||||
var listeningTimeToAdd = Math.max(0, Math.floor(this.listeningTimeSinceSync))
|
var listeningTimeToAdd = Math.max(0, Math.floor(this.listeningTimeSinceSync))
|
||||||
syncData = {
|
syncData = {
|
||||||
timeListened: listeningTimeToAdd,
|
timeListened: listeningTimeToAdd,
|
||||||
currentTime: this.player.getCurrentTime()
|
duration: this.getDuration(),
|
||||||
|
mediaEntityId: this.mediaEntityId,
|
||||||
|
currentTime: this.getCurrentTime()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.listeningTimeSinceSync = 0
|
this.listeningTimeSinceSync = 0
|
||||||
@ -224,6 +228,8 @@ export default class PlayerHandler {
|
|||||||
var listeningTimeToAdd = Math.max(0, Math.floor(this.listeningTimeSinceSync))
|
var listeningTimeToAdd = Math.max(0, Math.floor(this.listeningTimeSinceSync))
|
||||||
var syncData = {
|
var syncData = {
|
||||||
timeListened: listeningTimeToAdd,
|
timeListened: listeningTimeToAdd,
|
||||||
|
duration: this.getDuration(),
|
||||||
|
mediaEntityId: this.mediaEntityId,
|
||||||
currentTime
|
currentTime
|
||||||
}
|
}
|
||||||
this.listeningTimeSinceSync = 0
|
this.listeningTimeSinceSync = 0
|
||||||
|
@ -80,15 +80,23 @@ class PlaybackSessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async syncSession(user, session, syncData) {
|
async syncSession(user, session, syncData) {
|
||||||
|
var libraryItem = this.db.libraryItems.find(li => li.id === session.libraryItemId)
|
||||||
|
if (!libraryItem) {
|
||||||
|
Logger.error(`[PlaybackSessionManager] syncSession Library Item not found "${sessino.libraryItemId}"`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
session.currentTime = syncData.currentTime
|
session.currentTime = syncData.currentTime
|
||||||
session.addListeningTime(syncData.timeListened)
|
session.addListeningTime(syncData.timeListened)
|
||||||
Logger.debug(`[PlaybackSessionManager] syncSession "${session.id}" | Total Time Listened: ${session.timeListening}`)
|
Logger.debug(`[PlaybackSessionManager] syncSession "${session.id}" | Total Time Listened: ${session.timeListening}`)
|
||||||
|
|
||||||
const itemProgressUpdate = {
|
const itemProgressUpdate = {
|
||||||
|
mediaEntityId: syncData.mediaEntityId || null,
|
||||||
|
duration: syncData.duration,
|
||||||
currentTime: syncData.currentTime,
|
currentTime: syncData.currentTime,
|
||||||
progress: session.progress
|
progress: session.progress
|
||||||
}
|
}
|
||||||
var wasUpdated = user.createUpdateLibraryItemProgress(session.libraryItemId, itemProgressUpdate)
|
var wasUpdated = user.createUpdateLibraryItemProgress(libraryItem, itemProgressUpdate)
|
||||||
if (wasUpdated) {
|
if (wasUpdated) {
|
||||||
await this.db.updateEntity('user', user)
|
await this.db.updateEntity('user', user)
|
||||||
var itemProgress = user.getLibraryItemProgress(session.libraryItemId)
|
var itemProgress = user.getLibraryItemProgress(session.libraryItemId)
|
||||||
@ -112,6 +120,8 @@ class PlaybackSessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveSession(session) {
|
saveSession(session) {
|
||||||
|
if (!session.timeListening) return // Do not save a session with no listening time
|
||||||
|
|
||||||
if (session.lastSave) {
|
if (session.lastSave) {
|
||||||
return this.db.updateEntity('session', session)
|
return this.db.updateEntity('session', session)
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,7 +23,7 @@ class MeController {
|
|||||||
return res.sendStatus(200)
|
return res.sendStatus(200)
|
||||||
}
|
}
|
||||||
await this.db.updateEntity('user', req.user)
|
await this.db.updateEntity('user', req.user)
|
||||||
this.clientEmitter(req.user.id, 'user_item_progress_updated', { id: libraryItem.id, data: null })
|
// this.clientEmitter(req.user.id, 'user_item_progress_updated', { id: libraryItem.id, data: null })
|
||||||
|
|
||||||
this.clientEmitter(req.user.id, 'user_updated', req.user.toJSONForBrowser())
|
this.clientEmitter(req.user.id, 'user_updated', req.user.toJSONForBrowser())
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
@ -35,7 +35,7 @@ class MeController {
|
|||||||
if (!libraryItem) {
|
if (!libraryItem) {
|
||||||
return res.status(404).send('Item not found')
|
return res.status(404).send('Item not found')
|
||||||
}
|
}
|
||||||
var wasUpdated = req.user.createUpdateLibraryItemProgress(libraryItem.id, req.body)
|
var wasUpdated = req.user.createUpdateLibraryItemProgress(libraryItem, req.body)
|
||||||
if (wasUpdated) {
|
if (wasUpdated) {
|
||||||
await this.db.updateEntity('user', req.user)
|
await this.db.updateEntity('user', req.user)
|
||||||
this.clientEmitter(req.user.id, 'user_updated', req.user.toJSONForBrowser())
|
this.clientEmitter(req.user.id, 'user_updated', req.user.toJSONForBrowser())
|
||||||
@ -54,7 +54,7 @@ class MeController {
|
|||||||
itemProgressPayloads.forEach((itemProgress) => {
|
itemProgressPayloads.forEach((itemProgress) => {
|
||||||
var libraryItem = this.db.libraryItems.find(li => li.id === itemProgress.id) // Make sure this library item exists
|
var libraryItem = this.db.libraryItems.find(li => li.id === itemProgress.id) // Make sure this library item exists
|
||||||
if (libraryItem) {
|
if (libraryItem) {
|
||||||
var wasUpdated = req.user.createUpdateLibraryItemProgress(libraryItem.id, itemProgress)
|
var wasUpdated = req.user.createUpdateLibraryItemProgress(libraryItem, itemProgress)
|
||||||
if (wasUpdated) shouldUpdate = true
|
if (wasUpdated) shouldUpdate = true
|
||||||
} else {
|
} else {
|
||||||
Logger.error(`[MeController] batchUpdateLibraryItemProgress: Library Item does not exist ${itemProgress.id}`)
|
Logger.error(`[MeController] batchUpdateLibraryItemProgress: Library Item does not exist ${itemProgress.id}`)
|
||||||
|
@ -4,7 +4,9 @@ class LibraryItemProgress {
|
|||||||
constructor(progress) {
|
constructor(progress) {
|
||||||
this.id = null // Same as library item id
|
this.id = null // Same as library item id
|
||||||
this.libraryItemId = null
|
this.libraryItemId = null
|
||||||
|
this.mediaEntityId = null
|
||||||
|
|
||||||
|
this.duration = null
|
||||||
this.progress = null // 0 to 1
|
this.progress = null // 0 to 1
|
||||||
this.currentTime = null // seconds
|
this.currentTime = null // seconds
|
||||||
this.isFinished = false
|
this.isFinished = false
|
||||||
@ -22,6 +24,8 @@ class LibraryItemProgress {
|
|||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
libraryItemId: this.libraryItemId,
|
libraryItemId: this.libraryItemId,
|
||||||
|
mediaEntityId: this.mediaEntityId,
|
||||||
|
duration: this.duration,
|
||||||
progress: this.progress,
|
progress: this.progress,
|
||||||
currentTime: this.currentTime,
|
currentTime: this.currentTime,
|
||||||
isFinished: this.isFinished,
|
isFinished: this.isFinished,
|
||||||
@ -34,6 +38,8 @@ class LibraryItemProgress {
|
|||||||
construct(progress) {
|
construct(progress) {
|
||||||
this.id = progress.id
|
this.id = progress.id
|
||||||
this.libraryItemId = progress.libraryItemId
|
this.libraryItemId = progress.libraryItemId
|
||||||
|
this.mediaEntityId = progress.mediaEntityId || null
|
||||||
|
this.duration = progress.duration || 0
|
||||||
this.progress = progress.progress
|
this.progress = progress.progress
|
||||||
this.currentTime = progress.currentTime
|
this.currentTime = progress.currentTime
|
||||||
this.isFinished = !!progress.isFinished
|
this.isFinished = !!progress.isFinished
|
||||||
@ -46,9 +52,11 @@ class LibraryItemProgress {
|
|||||||
return !this.isFinished && this.progress > 0
|
return !this.isFinished && this.progress > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
setData(libraryItemId, progress) {
|
setData(libraryItemId, mediaEntityId, progress) {
|
||||||
this.id = libraryItemId
|
this.id = libraryItemId
|
||||||
this.libraryItemId = libraryItemId
|
this.libraryItemId = libraryItemId
|
||||||
|
this.mediaEntityId = mediaEntityId
|
||||||
|
this.duration = progress.duration || 0
|
||||||
this.progress = Math.min(1, (progress.progress || 0))
|
this.progress = Math.min(1, (progress.progress || 0))
|
||||||
this.currentTime = progress.currentTime || 0
|
this.currentTime = progress.currentTime || 0
|
||||||
this.isFinished = !!progress.isFinished || this.progress == 1
|
this.isFinished = !!progress.isFinished || this.progress == 1
|
||||||
|
@ -211,11 +211,20 @@ class User {
|
|||||||
return this.libraryItemProgress.find(lip => lip.id === libraryItemId)
|
return this.libraryItemProgress.find(lip => lip.id === libraryItemId)
|
||||||
}
|
}
|
||||||
|
|
||||||
createUpdateLibraryItemProgress(libraryItemId, updatePayload) {
|
createUpdateLibraryItemProgress(libraryItem, updatePayload) {
|
||||||
var itemProgress = this.libraryItemProgress.find(li => li.id === libraryItemId)
|
var itemProgress = this.libraryItemProgress.find(li => li.id === libraryItem.id)
|
||||||
if (!itemProgress) {
|
if (!itemProgress) {
|
||||||
var newItemProgress = new LibraryItemProgress()
|
var newItemProgress = new LibraryItemProgress()
|
||||||
newItemProgress.setData(libraryItemId, updatePayload)
|
|
||||||
|
var mediaEntity = null
|
||||||
|
if (updatePayload.mediaEntityId) mediaEntity = libraryItem.media.getMediaEntityById(updatePayload.mediaEntityId)
|
||||||
|
if (!mediaEntity) mediaEntity = libraryItem.media.getPlaybackMediaEntity()
|
||||||
|
if (!mediaEntity) {
|
||||||
|
Logger.error(`[User] createUpdateLibraryItemProgress invalid library item has no playback media entity "${libraryItem.id}"`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
newItemProgress.setData(libraryItem.id, mediaEntity.id, updatePayload)
|
||||||
this.libraryItemProgress.push(newItemProgress)
|
this.libraryItemProgress.push(newItemProgress)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -225,7 +234,7 @@ class User {
|
|||||||
|
|
||||||
removeLibraryItemProgress(libraryItemId) {
|
removeLibraryItemProgress(libraryItemId) {
|
||||||
if (!this.libraryItemProgress.some(lip => lip.id == libraryItemId)) return false
|
if (!this.libraryItemProgress.some(lip => lip.id == libraryItemId)) return false
|
||||||
this.libraryItemProgress = this.libraryItemProgress.filter(lip => lip != libraryItemId)
|
this.libraryItemProgress = this.libraryItemProgress.filter(lip => lip.id != libraryItemId)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,6 +338,8 @@ function cleanUserObject(db, userObj) {
|
|||||||
var liProgress = new LibraryItemProgress() // New Progress Object
|
var liProgress = new LibraryItemProgress() // New Progress Object
|
||||||
liProgress.id = userAudiobookData.audiobookId // This ID will be updated when library item is created
|
liProgress.id = userAudiobookData.audiobookId // This ID will be updated when library item is created
|
||||||
liProgress.libraryItemId = userAudiobookData.audiobookId
|
liProgress.libraryItemId = userAudiobookData.audiobookId
|
||||||
|
liProgress.mediaEntityId = userAudiobookData.audiobookId
|
||||||
|
liProgress.duration = userAudiobookData.totalDuration
|
||||||
liProgress.isFinished = !!userAudiobookData.isRead
|
liProgress.isFinished = !!userAudiobookData.isRead
|
||||||
Object.keys(liProgress.toJSON()).forEach((key) => {
|
Object.keys(liProgress.toJSON()).forEach((key) => {
|
||||||
if (userAudiobookData[key] !== undefined) {
|
if (userAudiobookData[key] !== undefined) {
|
||||||
|
Loading…
Reference in New Issue
Block a user