mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-16 04:14:58 +02:00
Adding download zip file, fix local cover art for m4b download
This commit is contained in:
parent
a7c538193c
commit
a56b3a8096
14 changed files with 625 additions and 113 deletions
|
@ -411,28 +411,48 @@ class Audiobook {
|
|||
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 }))
|
||||
// If 1 audio file without chapters, then no chapters will be set
|
||||
|
||||
var includedAudioFiles = this.audioFiles.filter(af => !af.exclude)
|
||||
if (includedAudioFiles.length === 1) {
|
||||
// 1 audio file with chapters
|
||||
if (includedAudioFiles[0].chapters) {
|
||||
this.chapters = includedAudioFiles[0].chapters.map(c => ({ ...c }))
|
||||
}
|
||||
} else {
|
||||
this.chapters = []
|
||||
var currTrackId = 0
|
||||
var currChapterId = 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
|
||||
includedAudioFiles.forEach((file) => {
|
||||
// If audio file has chapters use chapters
|
||||
if (file.chapters && file.chapters.length) {
|
||||
file.chapters.forEach((chapter) => {
|
||||
var chapterDuration = chapter.end - chapter.start
|
||||
if (chapterDuration > 0) {
|
||||
var title = `Chapter ${currChapterId}`
|
||||
if (chapter.title) {
|
||||
title += ` (${chapter.title})`
|
||||
}
|
||||
this.chapters.push({
|
||||
id: currChapterId++,
|
||||
start: currStartTime,
|
||||
end: currStartTime + chapterDuration,
|
||||
title
|
||||
})
|
||||
currStartTime += chapterDuration
|
||||
}
|
||||
})
|
||||
} else if (file.duration) {
|
||||
// Otherwise just use track has chapter
|
||||
this.chapters.push({
|
||||
id: currChapterId++,
|
||||
start: currStartTime,
|
||||
end: currStartTime + file.duration,
|
||||
title: `Chapter ${currChapterId}`
|
||||
})
|
||||
currStartTime += file.duration
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const DEFAULT_EXPIRATION = 1000 * 60 * 60 // 60 minutes
|
||||
|
||||
const DEFAULT_TIMEOUT = 1000 * 60 * 15 // 15 minutes
|
||||
class Download {
|
||||
constructor(download) {
|
||||
this.id = null
|
||||
|
@ -16,12 +16,17 @@ class Download {
|
|||
this.userId = null
|
||||
this.socket = null // Socket to notify when complete
|
||||
this.isReady = false
|
||||
this.isTimedOut = false
|
||||
|
||||
this.startedAt = null
|
||||
this.finishedAt = null
|
||||
this.expiresAt = null
|
||||
|
||||
this.expirationTimeMs = 0
|
||||
this.timeoutTimeMs = 0
|
||||
|
||||
this.timeoutTimer = null
|
||||
this.expirationTimer = null
|
||||
|
||||
if (download) {
|
||||
this.construct(download)
|
||||
|
@ -88,6 +93,8 @@ class Download {
|
|||
this.finishedAt = download.finishedAt || null
|
||||
|
||||
this.expirationTimeMs = download.expirationTimeMs || DEFAULT_EXPIRATION
|
||||
this.timeoutTimeMs = download.timeoutTimeMs || DEFAULT_TIMEOUT
|
||||
|
||||
this.expiresAt = download.expiresAt || null
|
||||
}
|
||||
|
||||
|
@ -105,11 +112,28 @@ class Download {
|
|||
}
|
||||
|
||||
setExpirationTimer(callback) {
|
||||
setTimeout(() => {
|
||||
this.expirationTimer = setTimeout(() => {
|
||||
if (callback) {
|
||||
callback(this)
|
||||
}
|
||||
}, this.expirationTimeMs)
|
||||
}
|
||||
|
||||
setTimeoutTimer(callback) {
|
||||
this.timeoutTimer = setTimeout(() => {
|
||||
if (callback) {
|
||||
this.isTimedOut = true
|
||||
callback(this)
|
||||
}
|
||||
}, this.timeoutTimeMs)
|
||||
}
|
||||
|
||||
clearTimeoutTimer() {
|
||||
clearTimeout(this.timeoutTimer)
|
||||
}
|
||||
|
||||
clearExpirationTimer() {
|
||||
clearTimeout(this.expirationTimer)
|
||||
}
|
||||
}
|
||||
module.exports = Download
|
Loading…
Add table
Add a link
Reference in a new issue