diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index 263e93b0..4acbec70 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -44,7 +44,7 @@ class LibraryController { if (req.query.include && req.query.include === 'filterdata') { return res.json({ filterdata: libraryHelpers.getDistinctFilterDataNew(req.libraryItems), - issues: libraryHelpers.getNumIssues(req.libraryItems), + issues: req.libraryItems.filter(li => li.hasIssues).length, library: req.library }) } @@ -439,7 +439,6 @@ class LibraryController { async stats(req, res) { var libraryItems = req.libraryItems - var authorsWithCount = libraryHelpers.getAuthorsWithCount(libraryItems) var genresWithCount = libraryHelpers.getGenresWithCount(libraryItems) var durationStats = libraryHelpers.getItemDurationStats(libraryItems) diff --git a/server/objects/LibraryItem.js b/server/objects/LibraryItem.js index d4252a6b..aafdb287 100644 --- a/server/objects/LibraryItem.js +++ b/server/objects/LibraryItem.js @@ -152,6 +152,10 @@ class LibraryItem { get hasMediaEntities() { return this.media.hasMediaEntities } + get hasIssues() { + if (this.isMissing || this.isInvalid) return true + return this.media.hasIssues + } // Data comes from scandir library item data setData(libraryMediaType, payload) { diff --git a/server/objects/entities/PodcastEpisode.js b/server/objects/entities/PodcastEpisode.js index cc961920..7cfa1a8b 100644 --- a/server/objects/entities/PodcastEpisode.js +++ b/server/objects/entities/PodcastEpisode.js @@ -43,6 +43,10 @@ class PodcastEpisode { get tracks() { return [this.audioFile] } + get duration() { + return this.audioFile.duration + } + get size() { return this.audioFile.metadata.size } // Only checks container format checkCanDirectPlay(payload) { diff --git a/server/objects/files/EBookFile.js b/server/objects/files/EBookFile.js index 70e790ae..18686bf2 100644 --- a/server/objects/files/EBookFile.js +++ b/server/objects/files/EBookFile.js @@ -15,7 +15,7 @@ class EBookFile { construct(file) { this.ino = file.ino - this.metadata = new FileMetadata(file) + this.metadata = new FileMetadata(file.metadata) this.ebookFormat = file.ebookFormat this.addedAt = file.addedAt this.updatedAt = file.updatedAt diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 2a49f004..c32df120 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -72,8 +72,12 @@ class Book { get size() { var total = 0 - this.audiobooks.forEach((ab) => total += ab.size) - this.ebooks.forEach((eb) => total += eb.size) + this.audiobooks.forEach((ab) => { + total += ab.size + }) + this.ebooks.forEach((eb) => { + total += eb.size + }) return total } get hasMediaEntities() { @@ -87,6 +91,9 @@ class Book { get hasEmbeddedCoverArt() { return this.audiobooks.some(ab => ab.hasEmbeddedCoverArt) } + get hasIssues() { + return this.audiobooks.some(ab => ab.missingParts.length) + } update(payload) { var json = this.toJSON() @@ -293,5 +300,24 @@ class Book { var audiobook = this.getCreateAudiobookVariant(variant) audiobook.audioFiles.push(audioFile) } + + getLongestDuration() { + if (!this.audiobooks.length) return 0 + var longest = 0 + this.audiobooks.forEach((ab) => { + if (ab.duration > longest) longest = ab.duration + }) + return longest + } + getTotalAudioTracks() { + var total = 0 + this.audiobooks.forEach((ab) => total += ab.tracks.length) + return total + } + getTotalDuration() { + var total = 0 + this.audiobooks.forEach((ab) => total += ab.duration) + return total + } } module.exports = Book \ No newline at end of file diff --git a/server/objects/mediaTypes/Podcast.js b/server/objects/mediaTypes/Podcast.js index 3107eb7e..946ac677 100644 --- a/server/objects/mediaTypes/Podcast.js +++ b/server/objects/mediaTypes/Podcast.js @@ -43,8 +43,7 @@ class Podcast { metadata: this.metadata.toJSON(), coverPath: this.coverPath, tags: [...this.tags], - episodes: this.episodes.map(e => e.toJSON()), - + episodes: this.episodes.map(e => e.toJSON()) } } @@ -54,19 +53,14 @@ class Podcast { metadata: this.metadata.toJSONExpanded(), coverPath: this.coverPath, tags: [...this.tags], - episodes: this.episodes.map(e => e.toJSON()), - + episodes: this.episodes.map(e => e.toJSON()) } } - get tracks() { - return [] - } - get duration() { - return 0 - } get size() { - return 0 + var total = 0 + this.episodes.forEach((ep) => total += ep.size) + return total } get hasMediaEntities() { return !!this.episodes.length @@ -77,6 +71,9 @@ class Podcast { get hasEmbeddedCoverArt() { return false } + get hasIssues() { + return false + } update(payload) { var json = this.toJSON() @@ -105,10 +102,6 @@ class Podcast { return true } - checkUpdateMissingTracks() { - return false - } - removeFileWithInode(inode) { return false } @@ -138,5 +131,23 @@ class Podcast { var payload = this.metadata.searchQuery(query) return payload || {} } + + getLongestDuration() { + if (!this.episodes.length) return 0 + var longest = 0 + this.episodes.forEach((ab) => { + if (ab.duration > longest) longest = ab.duration + }) + return longest + } + + getTotalAudioTracks() { + return this.episodes.length + } + getTotalDuration() { + var total = 0 + this.episodes.forEach((ep) => total += ep.duration) + return total + } } module.exports = Podcast \ No newline at end of file diff --git a/server/utils/dbMigration.js b/server/utils/dbMigration.js index 9134c638..ae05967c 100644 --- a/server/utils/dbMigration.js +++ b/server/utils/dbMigration.js @@ -286,7 +286,7 @@ async function migrateLibraryItems(db) { sessions = sessions.map(se => { var libraryItemWithAudiobook = libraryItems.find(li => li.media.getAudiobookById && !!li.media.getAudiobookById(se.mediaEntityId)) if (!libraryItemWithAudiobook) { - Logger.error('[dbMigration] Failed to find library item with audiobook id', audiobookId) + Logger.error('[dbMigration] Failed to find library item with audiobook id', se.mediaEntityId) return null } se.libraryItemId = libraryItemWithAudiobook.id diff --git a/server/utils/libraryHelpers.js b/server/utils/libraryHelpers.js index 211b8600..8df2d02a 100644 --- a/server/utils/libraryHelpers.js +++ b/server/utils/libraryHelpers.js @@ -241,13 +241,13 @@ module.exports = { }, getItemDurationStats(libraryItems) { - var sorted = sort(libraryItems).desc(li => li.media.duration) - var top10 = sorted.slice(0, 10).map(li => ({ title: li.media.metadata.title, duration: li.media.duration })).filter(i => i.duration > 0) + var sorted = sort(libraryItems).desc(li => li.media.getLongestDuration()) + var top10 = sorted.slice(0, 10).map(li => ({ title: li.media.metadata.title, duration: li.media.getLongestDuration() })).filter(i => i.duration > 0) var totalDuration = 0 var numAudioTracks = 0 libraryItems.forEach((li) => { - totalDuration += li.media.duration - numAudioTracks += (li.media.tracks || []).length + totalDuration += li.media.getTotalDuration() + numAudioTracks += li.media.getTotalAudioTracks() }) return { totalDuration, @@ -263,12 +263,4 @@ module.exports = { }) return totalSize }, - - getNumIssues(libraryItems) { - // TODO: Implement issues - return libraryItems.filter(li => li.isMissing).length - // return books.filter(ab => { - // return ab.numMissingParts || ab.numInvalidParts || ab.isMissing || ab.isInvalid - // }).length - } } \ No newline at end of file