diff --git a/client/players/AudioTrack.js b/client/players/AudioTrack.js index 6cf785e2..f364dad8 100644 --- a/client/players/AudioTrack.js +++ b/client/players/AudioTrack.js @@ -6,6 +6,7 @@ export default class AudioTrack { this.title = track.title || '' this.contentUrl = track.contentUrl || null this.mimeType = track.mimeType + this.metadata = track.metadata || {} this.userToken = userToken } diff --git a/server/managers/PlaybackSessionManager.js b/server/managers/PlaybackSessionManager.js index 42524e64..409e98c8 100644 --- a/server/managers/PlaybackSessionManager.js +++ b/server/managers/PlaybackSessionManager.js @@ -55,7 +55,7 @@ class PlaybackSessionManager { var audioTracks = [] if (shouldDirectPlay) { Logger.debug(`[PlaybackSessionManager] "${user.username}" starting direct play session for item "${libraryItem.id}"`) - audioTracks = libraryItem.getDirectPlayTracklist(libraryItem.id, episodeId) + audioTracks = libraryItem.getDirectPlayTracklist(episodeId) newPlaybackSession.playMethod = PlayMethod.DIRECTPLAY } else { Logger.debug(`[PlaybackSessionManager] "${user.username}" starting stream session for item "${libraryItem.id}"`) diff --git a/server/objects/LibraryItem.js b/server/objects/LibraryItem.js index d5c8672a..704a49d0 100644 --- a/server/objects/LibraryItem.js +++ b/server/objects/LibraryItem.js @@ -59,8 +59,10 @@ class LibraryItem { this.mediaType = libraryItem.mediaType if (this.mediaType === 'book') { this.media = new Book(libraryItem.media) + this.media.libraryItemId = this.id } else if (this.mediaType === 'podcast') { this.media = new Podcast(libraryItem.media) + this.media.libraryItemId = this.id } this.libraryFiles = libraryItem.libraryFiles.map(f => new LibraryFile(f)) @@ -163,9 +165,11 @@ class LibraryItem { if (libraryMediaType === 'podcast') { this.mediaType = 'podcast' this.media = new Podcast() + this.media.libraryItemId = this.id } else { this.mediaType = 'book' this.media = new Book() + this.media.libraryItemId = this.id } @@ -440,8 +444,8 @@ class LibraryItem { return this.media.searchQuery(query) } - getDirectPlayTracklist(libraryItemId, episodeId) { - return this.media.getDirectPlayTracklist(libraryItemId, episodeId) + getDirectPlayTracklist(episodeId) { + return this.media.getDirectPlayTracklist(episodeId) } } module.exports = LibraryItem \ No newline at end of file diff --git a/server/objects/files/AudioTrack.js b/server/objects/files/AudioTrack.js index 5e4b03be..4fa6ff8d 100644 --- a/server/objects/files/AudioTrack.js +++ b/server/objects/files/AudioTrack.js @@ -1,5 +1,6 @@ const Path = require('path') const { encodeUriPath } = require('../../utils/index') + class AudioTrack { constructor() { this.index = null @@ -8,6 +9,7 @@ class AudioTrack { this.title = null this.contentUrl = null this.mimeType = null + this.metadata = null } toJSON() { @@ -17,7 +19,8 @@ class AudioTrack { duration: this.duration, title: this.title, contentUrl: this.contentUrl, - mimeType: this.mimeType + mimeType: this.mimeType, + metadata: this.metadata ? this.metadata.toJSON() : null } } @@ -28,6 +31,7 @@ class AudioTrack { this.title = audioFile.metadata.filename || '' this.contentUrl = Path.join(`/s/item/${itemId}`, encodeUriPath(audioFile.metadata.relPath)) this.mimeType = audioFile.mimeType + this.metadata = audioFile.metadata.clone() } setFromStream(title, duration, contentUrl) { diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 63e4176b..6cbeec38 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -11,6 +11,7 @@ const EBookFile = require('../files/EBookFile') class Book { constructor(book) { + this.libraryItemId = null this.metadata = null this.coverPath = null @@ -30,6 +31,7 @@ class Book { } construct(book) { + this.libraryItemId = book.libraryItemId this.metadata = new BookMetadata(book.metadata) this.coverPath = book.coverPath this.tags = [...book.tags] @@ -43,6 +45,7 @@ class Book { toJSON() { return { + libraryItemId: this.libraryItemId, metadata: this.metadata.toJSON(), coverPath: this.coverPath, tags: [...this.tags], @@ -70,6 +73,7 @@ class Book { toJSONExpanded() { return { + libraryItemId: this.libraryItemId, metadata: this.metadata.toJSONExpanded(), coverPath: this.coverPath, tags: [...this.tags], @@ -106,8 +110,13 @@ class Book { return this.missingParts.length || this.audioFiles.some(af => af.invalid) } get tracks() { - - return this.audioFiles.filter(af => !af.exclude && !af.invalid) + var startOffset = 0 + return this.audioFiles.filter(af => !af.exclude && !af.invalid).map((af) => { + var audioTrack = new AudioTrack() + audioTrack.setData(this.libraryItemId, af, startOffset) + startOffset += audioTrack.duration + return audioTrack + }) } get duration() { var total = 0 @@ -395,18 +404,8 @@ class Book { return !this.tracks.some((t) => !supportedMimeTypes.includes(t.mimeType)) } - getDirectPlayTracklist(libraryItemId) { - var tracklist = [] - - var startOffset = 0 - this.tracks.forEach((audioFile) => { - var audioTrack = new AudioTrack() - audioTrack.setData(libraryItemId, audioFile, startOffset) - startOffset += audioTrack.duration - tracklist.push(audioTrack) - }) - - return tracklist + getDirectPlayTracklist() { + return this.tracks } getPlaybackTitle() { diff --git a/server/objects/mediaTypes/Podcast.js b/server/objects/mediaTypes/Podcast.js index 17e3aeb9..36031e7e 100644 --- a/server/objects/mediaTypes/Podcast.js +++ b/server/objects/mediaTypes/Podcast.js @@ -9,6 +9,7 @@ const naturalSort = createNewSortInstance({ class Podcast { constructor(podcast) { + this.libraryItemId = null this.metadata = null this.coverPath = null this.tags = [] @@ -26,6 +27,7 @@ class Podcast { } construct(podcast) { + this.libraryItemId = podcast.libraryItemId this.metadata = new PodcastMetadata(podcast.metadata) this.coverPath = podcast.coverPath this.tags = [...podcast.tags] @@ -36,6 +38,7 @@ class Podcast { toJSON() { return { + libraryItemId: this.libraryItemId, metadata: this.metadata.toJSON(), coverPath: this.coverPath, tags: [...this.tags], @@ -59,6 +62,7 @@ class Podcast { toJSONExpanded() { return { + libraryItemId: this.libraryItemId, metadata: this.metadata.toJSONExpanded(), coverPath: this.coverPath, tags: [...this.tags], @@ -172,10 +176,10 @@ class Podcast { return episode.checkCanDirectPlay(payload) } - getDirectPlayTracklist(libraryItemId, episodeId) { + getDirectPlayTracklist(episodeId) { var episode = this.episodes.find(ep => ep.id === episodeId) if (!episode) return false - return episode.getDirectPlayTracklist(libraryItemId) + return episode.getDirectPlayTracklist(this.libraryItemId) } addPodcastEpisode(podcastEpisode) { diff --git a/server/utils/dbMigration.js b/server/utils/dbMigration.js index 3dda4830..705f5517 100644 --- a/server/utils/dbMigration.js +++ b/server/utils/dbMigration.js @@ -192,6 +192,7 @@ function makeLibraryItemFromOldAb(audiobook) { bookMetadata.series = makeSeriesFromOldAb(audiobook.book) } + bookEntity.libraryItemId = libraryItem.id bookEntity.metadata = bookMetadata bookEntity.coverPath = cleanOldCoverPath(audiobook.book.coverFullPath) bookEntity.tags = [...audiobook.tags]