mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-22 11:49:37 +00:00
New data model Book media type contains Audiobooks updates
This commit is contained in:
parent
1dde02b170
commit
c4eeb1cfb7
30 changed files with 347 additions and 247 deletions
|
|
@ -106,7 +106,8 @@ class LibraryItem {
|
|||
isInvalid: !!this.isInvalid,
|
||||
mediaType: this.mediaType,
|
||||
media: this.media.toJSONMinified(),
|
||||
numFiles: this.libraryFiles.length
|
||||
numFiles: this.libraryFiles.length,
|
||||
size: this.size
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class Book {
|
|||
return hasUpdated
|
||||
}
|
||||
try {
|
||||
var { authorLF, authorFL } = parseAuthors(author)
|
||||
var { authorLF, authorFL } = parseAuthors.parse(author)
|
||||
var hasUpdated = authorLF !== this.authorLF || authorFL !== this.authorFL
|
||||
this.authorFL = authorFL || null
|
||||
this.authorLF = authorLF || null
|
||||
|
|
@ -155,7 +155,7 @@ class Book {
|
|||
return hasUpdated
|
||||
}
|
||||
try {
|
||||
var { authorFL } = parseAuthors(narrator)
|
||||
var { authorFL } = parseAuthors.parse(narrator)
|
||||
var hasUpdated = authorFL !== this.narratorFL
|
||||
this.narratorFL = authorFL || null
|
||||
return hasUpdated
|
||||
|
|
|
|||
|
|
@ -116,6 +116,10 @@ class Book {
|
|||
return true
|
||||
}
|
||||
|
||||
getAudiobookById(audiobookId) {
|
||||
return this.audiobooks.find(ab => ab.id === audiobookId)
|
||||
}
|
||||
|
||||
removeFileWithInode(inode) {
|
||||
var audiobookWithIno = this.audiobooks.find(ab => ab.findFileWithInode(inode))
|
||||
if (audiobookWithIno) {
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ class BookMetadata {
|
|||
language: this.language,
|
||||
explicit: this.explicit,
|
||||
authorName: this.authorName,
|
||||
authorNameLF: this.authorNameLF,
|
||||
narratorName: this.narratorName
|
||||
}
|
||||
}
|
||||
|
|
@ -95,6 +96,10 @@ class BookMetadata {
|
|||
if (!this.authors.length) return ''
|
||||
return this.authors.map(au => au.name).join(', ')
|
||||
}
|
||||
get authorNameLF() { // Last, First
|
||||
if (!this.authors.length) return ''
|
||||
return this.authors.map(au => parseNameString.nameToLastFirst(au.name)).join(', ')
|
||||
}
|
||||
get seriesName() {
|
||||
if (!this.series.length) return ''
|
||||
return this.series.map(se => {
|
||||
|
|
@ -243,13 +248,13 @@ class BookMetadata {
|
|||
|
||||
// Returns array of names in First Last format
|
||||
parseNarratorsTag(narratorsTag) {
|
||||
var parsed = parseNameString(narratorsTag)
|
||||
var parsed = parseNameString.parse(narratorsTag)
|
||||
return parsed ? parsed.names : []
|
||||
}
|
||||
|
||||
// Return array of authors minified with placeholder id
|
||||
parseAuthorsTag(authorsTag) {
|
||||
var parsed = parseNameString(authorsTag)
|
||||
var parsed = parseNameString.parse(authorsTag)
|
||||
if (!parsed) return []
|
||||
return (parsed.names || []).map((au) => {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ const Logger = require('../../Logger')
|
|||
class LibraryItemProgress {
|
||||
constructor(progress) {
|
||||
this.id = null // Same as library item id
|
||||
this.libararyItemId = null
|
||||
this.libraryItemId = null
|
||||
|
||||
this.totalDuration = null // seconds
|
||||
this.progress = null // 0 to 1
|
||||
this.currentTime = null // seconds
|
||||
this.isRead = false
|
||||
this.isFinished = false
|
||||
|
||||
this.lastUpdate = null
|
||||
this.startedAt = null
|
||||
|
|
@ -22,11 +22,11 @@ class LibraryItemProgress {
|
|||
toJSON() {
|
||||
return {
|
||||
id: this.id,
|
||||
libararyItemId: this.libararyItemId,
|
||||
libraryItemId: this.libraryItemId,
|
||||
totalDuration: this.totalDuration,
|
||||
progress: this.progress,
|
||||
currentTime: this.currentTime,
|
||||
isRead: this.isRead,
|
||||
isFinished: this.isFinished,
|
||||
lastUpdate: this.lastUpdate,
|
||||
startedAt: this.startedAt,
|
||||
finishedAt: this.finishedAt
|
||||
|
|
@ -35,11 +35,11 @@ class LibraryItemProgress {
|
|||
|
||||
construct(progress) {
|
||||
this.id = progress.id
|
||||
this.libararyItemId = progress.libararyItemId
|
||||
this.libraryItemId = progress.libraryItemId
|
||||
this.totalDuration = progress.totalDuration
|
||||
this.progress = progress.progress
|
||||
this.currentTime = progress.currentTime
|
||||
this.isRead = !!progress.isRead
|
||||
this.isFinished = !!progress.isFinished
|
||||
this.lastUpdate = progress.lastUpdate
|
||||
this.startedAt = progress.startedAt
|
||||
this.finishedAt = progress.finishedAt || null
|
||||
|
|
@ -59,11 +59,11 @@ class LibraryItemProgress {
|
|||
// If has < 10 seconds remaining mark as read
|
||||
var timeRemaining = this.totalDuration - this.currentTime
|
||||
if (timeRemaining < 10) {
|
||||
this.isRead = true
|
||||
this.isFinished = true
|
||||
this.progress = 1
|
||||
this.finishedAt = Date.now()
|
||||
} else {
|
||||
this.isRead = false
|
||||
this.isFinished = false
|
||||
this.finishedAt = null
|
||||
}
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ class LibraryItemProgress {
|
|||
var hasUpdates = false
|
||||
for (const key in payload) {
|
||||
if (this[key] !== undefined && payload[key] !== this[key]) {
|
||||
if (key === 'isRead') {
|
||||
if (key === 'isFinished') {
|
||||
if (!payload[key]) { // Updating to Not Read - Reset progress and current time
|
||||
this.finishedAt = null
|
||||
this.progress = 0
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
const Logger = require('../../Logger')
|
||||
const { isObject } = require('../../utils')
|
||||
const AudioBookmark = require('./AudioBookmark')
|
||||
const LibraryItemProgress = require('./LibraryItemProgress')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue