From 02c4b21d3fd3813e2c181e12b49e2a3d572b343f Mon Sep 17 00:00:00 2001 From: Lars Kiesow Date: Tue, 10 Jan 2023 21:50:33 +0100 Subject: [PATCH] Show next book only if previous book is finished MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch changes the books displayed in “Continue Series”, avoiding books if another book from the series is played back right now. This prevents Audiobookshelf suggesting books to which users will not listen to because they are still listening to the last one. Once a book is finished, the next book in the series will pop still be suggested to the user. This fixes #1382 --- server/utils/libraryHelpers.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/utils/libraryHelpers.js b/server/utils/libraryHelpers.js index 1e480845..49d5264c 100644 --- a/server/utils/libraryHelpers.js +++ b/server/utils/libraryHelpers.js @@ -499,6 +499,7 @@ module.exports = { for (const librarySeries of libraryItem.media.metadata.series) { const mediaProgress = allItemProgress.length ? allItemProgress[0] : null const bookInProgress = mediaProgress && (mediaProgress.inProgress || mediaProgress.isFinished) + const bookActive = mediaProgress && mediaProgress.inProgress && !mediaProgress.isFinished const libraryItemJson = libraryItem.toJSONMinified() libraryItemJson.seriesSequence = librarySeries.sequence @@ -511,6 +512,7 @@ module.exports = { ...seriesObj.toJSON(), books: [libraryItemJson], inProgress: bookInProgress, + hasActiveBook: bookActive, hideFromContinueListening, bookInProgressLastUpdate: bookInProgress ? mediaProgress.lastUpdate : null, firstBookUnread: bookInProgress ? null : libraryItemJson @@ -553,6 +555,11 @@ module.exports = { seriesMap[librarySeries.id].firstBookUnread = libraryItemJson } } + + // Update if series has an active (progress < 100%) book + if (bookActive) { + seriesMap[librarySeries.id].hasActiveBook = true + } } } } @@ -648,10 +655,12 @@ module.exports = { if (seriesMap[seriesId].inProgress && !seriesMap[seriesId].hideFromContinueListening) { seriesMap[seriesId].books = naturalSort(seriesMap[seriesId].books).asc(li => li.seriesSequence) - // NEW implementation takes the first book unread with the smallest series sequence + // take the first book unread with the smallest series sequence + // unless the user is already listening to a book from this series + const hasActiveBook = seriesMap[seriesId].hasActiveBook const nextBookInSeries = seriesMap[seriesId].firstBookUnread - if (nextBookInSeries) { + if (!hasActiveBook && nextBookInSeries) { const bookForContinueSeries = { ...nextBookInSeries, prevBookInProgressLastUpdate: seriesMap[seriesId].bookInProgressLastUpdate