Update:When merging embedded chapters from multiple files filter out ~0 duration chapters #3361

This commit is contained in:
advplyr 2024-09-24 10:54:25 -05:00
parent 5b22e945da
commit bb7938f66d

View File

@ -475,16 +475,26 @@ class AudioFileScanner {
audioFiles.forEach((file) => { audioFiles.forEach((file) => {
if (file.duration) { if (file.duration) {
const afChapters = // Multi-file audiobook may include the previous and next chapters embedded with close to 0 duration
file.chapters?.map((c) => ({ // Filter these out and log a warning
...c, // See https://github.com/advplyr/audiobookshelf/issues/3361
id: c.id + currChapterId, const afChaptersCleaned =
start: c.start + currStartTime, file.chapters?.filter((c) => {
end: c.end + currStartTime if (c.end - c.start < 0.1) {
})) ?? [] libraryScan.addLog(LogLevel.WARN, `Chapter "${c.title}" has invalid duration of ${c.end - c.start} seconds. Skipping this chapter.`)
return false
}
return true
}) || []
const afChapters = afChaptersCleaned.map((c) => ({
...c,
id: c.id + currChapterId,
start: c.start + currStartTime,
end: c.end + currStartTime
}))
chapters = chapters.concat(afChapters) chapters = chapters.concat(afChapters)
currChapterId += file.chapters?.length ?? 0 currChapterId += afChaptersCleaned.length ?? 0
currStartTime += file.duration currStartTime += file.duration
} }
}) })