mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-03 09:44:41 +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
|
@ -20,6 +20,7 @@ class AudioFile {
|
|||
this.timeBase = null
|
||||
this.channels = null
|
||||
this.channelLayout = null
|
||||
this.chapters = []
|
||||
|
||||
this.tagAlbum = null
|
||||
this.tagArtist = null
|
||||
|
@ -60,6 +61,7 @@ class AudioFile {
|
|||
timeBase: this.timeBase,
|
||||
channels: this.channels,
|
||||
channelLayout: this.channelLayout,
|
||||
chapters: this.chapters,
|
||||
tagAlbum: this.tagAlbum,
|
||||
tagArtist: this.tagArtist,
|
||||
tagGenre: this.tagGenre,
|
||||
|
@ -93,6 +95,7 @@ class AudioFile {
|
|||
this.timeBase = data.timeBase
|
||||
this.channels = data.channels
|
||||
this.channelLayout = data.channelLayout
|
||||
this.chapters = data.chapters
|
||||
|
||||
this.tagAlbum = data.tagAlbum
|
||||
this.tagArtist = data.tagArtist
|
||||
|
@ -121,12 +124,13 @@ class AudioFile {
|
|||
this.format = data.format
|
||||
this.duration = data.duration
|
||||
this.size = data.size
|
||||
this.bitRate = data.bit_rate
|
||||
this.bitRate = data.bit_rate || null
|
||||
this.language = data.language
|
||||
this.codec = data.codec
|
||||
this.timeBase = data.time_base
|
||||
this.channels = data.channels
|
||||
this.channelLayout = data.channel_layout
|
||||
this.chapters = data.chapters || []
|
||||
|
||||
this.tagAlbum = data.file_tag_album || null
|
||||
this.tagArtist = data.file_tag_artist || null
|
||||
|
|
|
@ -97,12 +97,12 @@ class AudioTrack {
|
|||
this.format = probeData.format
|
||||
this.duration = probeData.duration
|
||||
this.size = probeData.size
|
||||
this.bitRate = probeData.bit_rate
|
||||
this.bitRate = probeData.bitRate
|
||||
this.language = probeData.language
|
||||
this.codec = probeData.codec
|
||||
this.timeBase = probeData.time_base
|
||||
this.timeBase = probeData.timeBase
|
||||
this.channels = probeData.channels
|
||||
this.channelLayout = probeData.channel_layout
|
||||
this.channelLayout = probeData.channelLayout
|
||||
|
||||
this.tagAlbum = probeData.file_tag_album || null
|
||||
this.tagArtist = probeData.file_tag_artist || null
|
||||
|
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
const DEFAULT_EXPIRATION = 1000 * 60 * 10 // 10 minutes
|
||||
const DEFAULT_EXPIRATION = 1000 * 60 * 60 // 60 minutes
|
||||
|
||||
class Download {
|
||||
constructor(download) {
|
||||
|
|
|
@ -191,7 +191,7 @@ class Stream extends EventEmitter {
|
|||
|
||||
this.socket.emit('stream_progress', {
|
||||
stream: this.id,
|
||||
percentCreated: perc,
|
||||
percent: perc,
|
||||
chunks,
|
||||
numSegments: this.numSegments
|
||||
})
|
||||
|
@ -201,7 +201,7 @@ class Stream extends EventEmitter {
|
|||
}
|
||||
|
||||
startLoop() {
|
||||
this.socket.emit('stream_progress', { chunks: [], numSegments: 0 })
|
||||
this.socket.emit('stream_progress', { stream: this.id, chunks: [], numSegments: 0, percent: '0%' })
|
||||
this.loop = setInterval(() => {
|
||||
if (!this.isTranscodeComplete) {
|
||||
this.checkFiles()
|
||||
|
@ -230,8 +230,9 @@ class Stream extends EventEmitter {
|
|||
this.ffmpeg.inputOption('-noaccurate_seek')
|
||||
}
|
||||
|
||||
const logLevel = process.env.NODE_ENV === 'production' ? 'error' : 'warning'
|
||||
this.ffmpeg.addOption([
|
||||
'-loglevel warning',
|
||||
`-loglevel ${logLevel}`,
|
||||
'-map 0:a',
|
||||
'-c:a copy'
|
||||
])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue