Fix player content url, update user progress object include media entity id, update reset progress route

This commit is contained in:
advplyr 2022-03-18 15:31:46 -05:00
parent 3d2bbc7719
commit 6a06ba4327
10 changed files with 65 additions and 35 deletions

View file

@ -259,7 +259,6 @@ export default {
this.$store.commit('users/updateUser', user)
},
userItemProgressUpdate(payload) {
console.log('User item progress update', payload)
this.$store.commit('user/updateItemProgress', payload)
},
collectionAdded(collection) {

View file

@ -117,7 +117,6 @@ export default {
var errorMsg = err.response ? err.response.data || 'Unknown Error' : 'Unknown Error'
this.$toast.error(`Failed to get library stats: ${errorMsg}`)
})
console.log('lib stats', this.libraryStats)
}
},
mounted() {

View file

@ -30,7 +30,6 @@
</h1>
<p v-if="subtitle" class="sm:ml-4 text-gray-400 text-xl md:text-2xl">{{ subtitle }}</p>
</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">
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">,&nbsp;</span></nuxt-link>
@ -69,7 +68,7 @@
</template>
</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">
<span class="text-white text-opacity-60 uppercase text-sm">Duration</span>
</div>
@ -77,7 +76,7 @@
{{ durationPretty }}
</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">
<span class="text-white text-opacity-60 uppercase text-sm">Size</span>
</div>
@ -220,6 +219,10 @@ export default {
audiobooks() {
return this.media.audiobooks || []
},
defaultAudiobook() {
if (!this.audiobooks.length) return null
return this.audiobooks[0]
},
title() {
return this.mediaMetadata.title || 'No Title'
},
@ -258,33 +261,28 @@ export default {
})
},
durationPretty() {
return this.$elapsedPretty(this.media.duration)
if (!this.defaultAudiobook) return 'N/A'
return this.$elapsedPretty(this.defaultAudiobook.duration)
},
duration() {
return this.media.duration
if (!this.defaultAudiobook) return 0
return this.defaultAudiobook.duration
},
sizePretty() {
return this.$bytesPretty(this.media.size)
if (!this.defaultAudiobook) return 'N/A'
return this.$bytesPretty(this.defaultAudiobook.size)
},
libraryFiles() {
return this.libraryItem.libraryFiles || []
},
otherAudioFiles() {
return this.audioFiles.filter((af) => {
return !this.tracks.find((t) => t.path === af.path)
})
},
tracks() {
return this.media.tracks || []
},
audioFiles() {
return this.media.audioFiles || []
audiobooks() {
return this.media.audiobooks || []
},
ebooks() {
return this.media.ebooks || []
},
showExperimentalReadAlert() {
return !this.tracks.length && this.ebooks.length && !this.showExperimentalFeatures
return !this.audiobooks.length && this.ebooks.length && !this.showExperimentalFeatures
},
description() {
return this.mediaMetadata.description || ''
@ -292,14 +290,13 @@ export default {
userItemProgress() {
return this.$store.getters['user/getUserLibraryItemProgress'](this.libraryItemId)
},
userCurrentTime() {
return this.userItemProgress ? this.userItemProgress.currentTime : 0
},
userIsFinished() {
return this.userItemProgress ? !!this.userItemProgress.isFinished : false
},
userTimeRemaining() {
return this.duration - this.userCurrentTime
if (!this.userItemProgress) return 0
var duration = this.userItemProgress.duration || this.duration
return duration - this.userItemProgress.currentTime
},
progressPercent() {
return this.userItemProgress ? Math.max(Math.min(1, this.userItemProgress.progress), 0) : 0

View file

@ -26,6 +26,6 @@ export default class AudioTrack {
return `${process.env.serverUrl}${this.contentUrl}?token=${this.userToken}`
}
return this.contentUrl + '?token=${this.userToken}'
return this.contentUrl + `?token=${this.userToken}`
}
}

View file

@ -11,6 +11,7 @@ export default class PlayerHandler {
this.playerState = 'IDLE'
this.isHlsTranscode = false
this.currentSessionId = null
this.mediaEntityId = null
this.startTime = 0
this.lastSyncTime = 0
@ -107,7 +108,7 @@ export default class PlayerHandler {
this.stopPlayInterval()
}
if (this.playerState === 'LOADED' || this.playerState === 'PLAYING') {
this.ctx.setDuration(this.player.getDuration())
this.ctx.setDuration(this.getDuration())
}
if (this.playerState !== 'LOADING') {
this.ctx.setCurrentTime(this.player.getCurrentTime())
@ -149,6 +150,7 @@ export default class PlayerHandler {
prepareSession(session) {
this.startTime = session.currentTime
this.currentSessionId = session.id
this.mediaEntityId = session.mediaEntityId
console.log('[PlayerHandler] Preparing Session', session)
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))
syncData = {
timeListened: listeningTimeToAdd,
currentTime: this.player.getCurrentTime()
duration: this.getDuration(),
mediaEntityId: this.mediaEntityId,
currentTime: this.getCurrentTime()
}
}
this.listeningTimeSinceSync = 0
@ -224,6 +228,8 @@ export default class PlayerHandler {
var listeningTimeToAdd = Math.max(0, Math.floor(this.listeningTimeSinceSync))
var syncData = {
timeListened: listeningTimeToAdd,
duration: this.getDuration(),
mediaEntityId: this.mediaEntityId,
currentTime
}
this.listeningTimeSinceSync = 0