mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-02 01:05:25 +02:00
Adding chapters and downloading m4b file
This commit is contained in:
parent
26d922d3dc
commit
315de87bfc
24 changed files with 311 additions and 69 deletions
|
@ -26,6 +26,7 @@ class Audiobook {
|
|||
|
||||
this.tags = []
|
||||
this.book = null
|
||||
this.chapters = []
|
||||
|
||||
if (audiobook) {
|
||||
this.construct(audiobook)
|
||||
|
@ -51,6 +52,9 @@ class Audiobook {
|
|||
if (audiobook.book) {
|
||||
this.book = new Book(audiobook.book)
|
||||
}
|
||||
if (audiobook.chapters) {
|
||||
this.chapters = audiobook.chapters.map(c => ({ ...c }))
|
||||
}
|
||||
}
|
||||
|
||||
get title() {
|
||||
|
@ -122,7 +126,8 @@ class Audiobook {
|
|||
book: this.bookToJSON(),
|
||||
tracks: this.tracksToJSON(),
|
||||
audioFiles: (this.audioFiles || []).map(audioFile => audioFile.toJSON()),
|
||||
otherFiles: (this.otherFiles || []).map(otherFile => otherFile.toJSON())
|
||||
otherFiles: (this.otherFiles || []).map(otherFile => otherFile.toJSON()),
|
||||
chapters: this.chapters || []
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +146,8 @@ class Audiobook {
|
|||
hasBookMatch: !!this.book,
|
||||
hasMissingParts: this.missingParts ? this.missingParts.length : 0,
|
||||
hasInvalidParts: this.invalidParts ? this.invalidParts.length : 0,
|
||||
numTracks: this.tracks.length
|
||||
numTracks: this.tracks.length,
|
||||
chapters: this.chapters || []
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,7 +168,8 @@ class Audiobook {
|
|||
otherFiles: (this.otherFiles || []).map(otherFile => otherFile.toJSON()),
|
||||
tags: this.tags,
|
||||
book: this.bookToJSON(),
|
||||
tracks: this.tracksToJSON()
|
||||
tracks: this.tracksToJSON(),
|
||||
chapters: this.chapters || []
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -403,5 +410,31 @@ class Audiobook {
|
|||
getAudioFileByIno(ino) {
|
||||
return this.audioFiles.find(af => af.ino === ino)
|
||||
}
|
||||
|
||||
setChaptersFromAudioFile(audioFile) {
|
||||
if (!audioFile.chapters) return []
|
||||
return audioFile.chapters.map(c => ({ ...c }))
|
||||
}
|
||||
|
||||
setChapters() {
|
||||
if (this.audioFiles.length === 1) {
|
||||
if (this.audioFiles[0].chapters) {
|
||||
this.chapters = this.audioFiles[0].chapters.map(c => ({ ...c }))
|
||||
}
|
||||
} else {
|
||||
this.chapters = []
|
||||
var currTrackId = 0
|
||||
var currStartTime = 0
|
||||
this.tracks.forEach((track) => {
|
||||
this.chapters.push({
|
||||
id: currTrackId++,
|
||||
start: currStartTime,
|
||||
end: currStartTime + track.duration,
|
||||
title: `Chapter ${currTrackId}`
|
||||
})
|
||||
currStartTime += track.duration
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = Audiobook
|
Loading…
Add table
Add a link
Reference in a new issue