mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-15 11:54:56 +02:00
New data model fix library stats
This commit is contained in:
parent
57399bb79e
commit
eea3e2583c
8 changed files with 69 additions and 33 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue