Skip to content

Commit

Permalink
Fix merging embedded chapters for multi-track audiobooks giving incor…
Browse files Browse the repository at this point in the history
…rect chapter ids #3361

- Also trim chapter titles on probe (remove carriage return)
  • Loading branch information
advplyr committed Jan 12, 2025
1 parent 0da9a04 commit 64e9ac9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions server/scanner/AudioFileScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,17 @@ class AudioFileScanner {
// Filter these out and log a warning
// See https://github.com/advplyr/audiobookshelf/issues/3361
const afChaptersCleaned =
file.chapters?.filter((c) => {
file.chapters?.filter((c, i) => {
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.`)
libraryScan.addLog(LogLevel.WARN, `Audio file "${file.metadata.filename}" Chapter "${c.title}" (index ${i}) has invalid duration of ${c.end - c.start} seconds. Skipping this chapter.`)
return false
}
return true
}) || []
const afChapters = afChaptersCleaned.map((c) => ({

const afChapters = afChaptersCleaned.map((c, i) => ({
...c,
id: c.id + currChapterId,
id: currChapterId + i,
start: c.start + currStartTime,
end: c.end + currStartTime
}))
Expand Down
1 change: 1 addition & 0 deletions server/utils/prober.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function parseChapters(_chapters) {
.map((chap) => {
let title = chap['TAG:title'] || chap.title || ''
if (!title && chap.tags?.title) title = chap.tags.title
title = title.trim()

const timebase = chap.time_base?.includes('/') ? Number(chap.time_base.split('/')[1]) : 1
const start = !isNullOrNaN(chap.start_time) ? Number(chap.start_time) : !isNullOrNaN(chap.start) ? Number(chap.start) / timebase : 0
Expand Down

0 comments on commit 64e9ac9

Please sign in to comment.