From 80ef8ee890949b860585331e6c73a3a71b3e5912 Mon Sep 17 00:00:00 2001 From: Joakim Ramer Date: Sun, 29 Jan 2023 23:57:37 +0100 Subject: [PATCH 1/6] Fixes m4b chapters only taken from first file. --- server/objects/mediaTypes/Book.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 2e536a26..506e6ee7 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -421,9 +421,26 @@ class Book { } // IF first audio file has embedded chapters then use embedded chapters - if (includedAudioFiles[0].chapters && includedAudioFiles[0].chapters.length) { - Logger.debug(`[Book] setChapters: Using embedded chapters in audio file ${includedAudioFiles[0].metadata.path}`) - this.chapters = includedAudioFiles[0].chapters.map(c => ({ ...c })) + if (includedAudioFiles[0].chapters?.length) { + Logger.debug(`[Book] setChapters: Using embedded chapters in audio file ${includedAudioFiles[0]?.metadata?.path}`) + this.chapters = [] + let currChapterId = 0 + let currStartTime = 0 + + includedAudioFiles.forEach((file) => { + if (file.duration) { + let chapters = file.chapters?.map((c) => ({ + ...c, + id: c.id + currChapterId, + start: c.start + currStartTime, + end: c.end + currStartTime, + })) + this.chapters = this.chapters.concat(chapters) + + currChapterId += file.chapters?.length ?? 0 + currStartTime += file.duration + } + }) } else if (includedAudioFiles.length > 1) { // Build chapters from audio files this.chapters = [] @@ -461,4 +478,4 @@ class Book { return this.metadata.authorName } } -module.exports = Book \ No newline at end of file +module.exports = Book From 36d2957fb4db0d89198a4fe1751b772d2cb30c62 Mon Sep 17 00:00:00 2001 From: Joakim Ramer Date: Mon, 30 Jan 2023 12:46:41 +0100 Subject: [PATCH 2/6] Adds check for duplicated chapter data --- server/objects/mediaTypes/Book.js | 46 +++++++++++++++++++------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 506e6ee7..87bb5864 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -420,27 +420,37 @@ class Book { } } - // IF first audio file has embedded chapters then use embedded chapters + // If first audio file has embedded chapters then use embedded chapters if (includedAudioFiles[0].chapters?.length) { - Logger.debug(`[Book] setChapters: Using embedded chapters in audio file ${includedAudioFiles[0]?.metadata?.path}`) - this.chapters = [] - let currChapterId = 0 - let currStartTime = 0 + // If all files chapters are the same, then only make chapters for the first file + if ( + includedAudioFiles.length > 1 && + includedAudioFiles[0].chapters.length === includedAudioFiles[1].chapters.length && + includedAudioFiles[0].chapters.every((c, i) => c.title === includedAudioFiles[1].chapters[i].title) + ) { + Logger.debug(`[Book] setChapters: Using embedded chapters in first audio file ${includedAudioFiles[0].metadata?.path}`) + this.chapters = includedAudioFiles[0].chapters.map((c) => ({ ...c })) + } else { + Logger.debug(`[Book] setChapters: Using embedded chapters from all audio files ${includedAudioFiles[0].metadata?.path}`) + this.chapters = [] + let currChapterId = 0 + let currStartTime = 0 - includedAudioFiles.forEach((file) => { - if (file.duration) { - let chapters = file.chapters?.map((c) => ({ - ...c, - id: c.id + currChapterId, - start: c.start + currStartTime, - end: c.end + currStartTime, - })) - this.chapters = this.chapters.concat(chapters) + includedAudioFiles.forEach((file) => { + if (file.duration) { + let chapters = file.chapters?.map((c) => ({ + ...c, + id: c.id + currChapterId, + start: c.start + currStartTime, + end: c.end + currStartTime, + })) + this.chapters = this.chapters.concat(chapters) - currChapterId += file.chapters?.length ?? 0 - currStartTime += file.duration - } - }) + currChapterId += file.chapters?.length ?? 0 + currStartTime += file.duration + } + }) + } } else if (includedAudioFiles.length > 1) { // Build chapters from audio files this.chapters = [] From 72d0b097ab373ef933f723381597f857bf1fd59b Mon Sep 17 00:00:00 2001 From: Joakim Ramer Date: Mon, 30 Jan 2023 12:48:50 +0100 Subject: [PATCH 3/6] Reverts change of file ending --- server/objects/mediaTypes/Book.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 87bb5864..011a13eb 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -488,4 +488,4 @@ class Book { return this.metadata.authorName } } -module.exports = Book +module.exports = Book \ No newline at end of file From 5d96b2cc6e165dad812c1b0d4438afc387f1fc48 Mon Sep 17 00:00:00 2001 From: Joakim Ramer Date: Mon, 30 Jan 2023 12:56:22 +0100 Subject: [PATCH 4/6] Logs correctly and simplifies for single audio file. --- server/objects/mediaTypes/Book.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 011a13eb..9637eb50 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -424,8 +424,9 @@ class Book { if (includedAudioFiles[0].chapters?.length) { // If all files chapters are the same, then only make chapters for the first file if ( + includedAudioFiles.length === 1 || includedAudioFiles.length > 1 && - includedAudioFiles[0].chapters.length === includedAudioFiles[1].chapters.length && + includedAudioFiles[0].chapters.length === includedAudioFiles[1].chapters?.length && includedAudioFiles[0].chapters.every((c, i) => c.title === includedAudioFiles[1].chapters[i].title) ) { Logger.debug(`[Book] setChapters: Using embedded chapters in first audio file ${includedAudioFiles[0].metadata?.path}`) From 4770be5a397253b0a183787af293bb8752d86542 Mon Sep 17 00:00:00 2001 From: advplyr <67830747+advplyr@users.noreply.github.com> Date: Mon, 30 Jan 2023 17:50:45 -0600 Subject: [PATCH 5/6] Update server/objects/mediaTypes/Book.js --- server/objects/mediaTypes/Book.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 9637eb50..aaaa523e 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -439,7 +439,7 @@ class Book { includedAudioFiles.forEach((file) => { if (file.duration) { - let chapters = file.chapters?.map((c) => ({ + const chapters = file.chapters?.map((c) => ({ ...c, id: c.id + currChapterId, start: c.start + currStartTime, From 0203f9cc1b37b5dda029858e62a5ad216774e6ec Mon Sep 17 00:00:00 2001 From: advplyr <67830747+advplyr@users.noreply.github.com> Date: Mon, 30 Jan 2023 17:50:50 -0600 Subject: [PATCH 6/6] Update server/objects/mediaTypes/Book.js --- server/objects/mediaTypes/Book.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index aaaa523e..bc34bbb8 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -444,7 +444,7 @@ class Book { id: c.id + currChapterId, start: c.start + currStartTime, end: c.end + currStartTime, - })) + })) ?? [] this.chapters = this.chapters.concat(chapters) currChapterId += file.chapters?.length ?? 0