Change: audio player shows time remaining and percent #122, Add: experimental bookmarks start #115

This commit is contained in:
advplyr 2021-10-24 18:25:44 -05:00
parent f9bf846b30
commit c5eafdfa8a
9 changed files with 284 additions and 21 deletions

View file

@ -1,3 +1,5 @@
const AudioBookmark = require('./AudioBookmark')
class AudiobookProgress {
constructor(progress) {
this.audiobookId = null
@ -10,12 +12,18 @@ class AudiobookProgress {
this.lastUpdate = null
this.startedAt = null
this.finishedAt = null
this.bookmarks = []
if (progress) {
this.construct(progress)
}
}
bookmarksToJSON() {
if (!this.bookmarks) return []
return this.bookmarks.map(b => b.toJSON())
}
toJSON() {
return {
audiobookId: this.audiobookId,
@ -25,7 +33,8 @@ class AudiobookProgress {
isRead: this.isRead,
lastUpdate: this.lastUpdate,
startedAt: this.startedAt,
finishedAt: this.finishedAt
finishedAt: this.finishedAt,
bookmarks: this.bookmarksToJSON()
}
}
@ -38,6 +47,11 @@ class AudiobookProgress {
this.lastUpdate = progress.lastUpdate
this.startedAt = progress.startedAt
this.finishedAt = progress.finishedAt || null
if (progress.bookmarks) {
this.bookmarks = progress.bookmarks.map(b => new AudioBookmark(b))
} else {
this.bookmarks = []
}
}
updateFromStream(stream) {
@ -90,5 +104,12 @@ class AudiobookProgress {
}
return hasUpdates
}
createBookmark(time, title) {
var newBookmark = new AudioBookmark()
newBookmark.setData(time, title)
this.bookmarks.push(newBookmark)
return newBookmark
}
}
module.exports = AudiobookProgress