From f4f5f79af7b166c267ac2b9782005090b145d085 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 20 May 2023 13:30:07 -0500 Subject: [PATCH] Update:Add chapters to playback session so they can be used for podcast episodes in mobile apps --- server/objects/PlaybackSession.js | 2 +- server/objects/mediaTypes/Book.js | 4 ++++ server/objects/mediaTypes/Podcast.js | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/objects/PlaybackSession.js b/server/objects/PlaybackSession.js index b4daa026..232487f4 100644 --- a/server/objects/PlaybackSession.js +++ b/server/objects/PlaybackSession.js @@ -177,7 +177,7 @@ class PlaybackSession { this.episodeId = episodeId this.mediaType = libraryItem.mediaType this.mediaMetadata = libraryItem.media.metadata.clone() - this.chapters = (libraryItem.media.chapters || []).map(c => ({ ...c })) // Only book mediaType has chapters + this.chapters = libraryItem.media.getChapters(episodeId) this.displayTitle = libraryItem.media.getPlaybackTitle(episodeId) this.displayAuthor = libraryItem.media.getPlaybackAuthor() this.coverPath = libraryItem.media.coverPath diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 5d549970..c1e4dc99 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -528,5 +528,9 @@ class Book { getPlaybackAuthor() { return this.metadata.authorName } + + getChapters() { + return this.chapters?.map(ch => ({ ...ch })) || [] + } } module.exports = Book diff --git a/server/objects/mediaTypes/Podcast.js b/server/objects/mediaTypes/Podcast.js index e1227deb..47364f8a 100644 --- a/server/objects/mediaTypes/Podcast.js +++ b/server/objects/mediaTypes/Podcast.js @@ -339,5 +339,9 @@ class Podcast { if (!audioFile?.metaTags) return false return this.metadata.setDataFromAudioMetaTags(audioFile.metaTags, overrideExistingDetails) } + + getChapters(episodeId) { + return this.getEpisode(episodeId)?.chapters?.map(ch => ({ ...ch })) || [] + } } module.exports = Podcast