mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-02 17:24:57 +02:00
New data model scanner update and change scan chunks to be based on total file size
This commit is contained in:
parent
14a8f84446
commit
f00b120e96
6 changed files with 94 additions and 36 deletions
|
@ -141,6 +141,11 @@ class LibraryItem {
|
|||
this.libraryFiles.forEach((lf) => total += lf.metadata.size)
|
||||
return total
|
||||
}
|
||||
get audioFileTotalSize() {
|
||||
var total = 0
|
||||
this.libraryFiles.filter(lf => lf.fileType == 'audio').forEach((lf) => total += lf.metadata.size)
|
||||
return total
|
||||
}
|
||||
get hasAudioFiles() {
|
||||
return this.libraryFiles.some(lf => lf.fileType === 'audio')
|
||||
}
|
||||
|
@ -347,7 +352,9 @@ class LibraryItem {
|
|||
return true
|
||||
})
|
||||
if (filesRemoved.length) {
|
||||
this.media.checkUpdateMissingTracks()
|
||||
if (this.media.audiobooks && this.media.audiobooks.length) {
|
||||
this.media.audiobooks.forEach(ab => ab.checkUpdateMissingTracks())
|
||||
}
|
||||
hasUpdated = true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const Path = require('path')
|
||||
const AudioFile = require('../files/AudioFile')
|
||||
const { areEquivalent, copyValue } = require('../../utils/index')
|
||||
const { areEquivalent, copyValue, getId } = require('../../utils/index')
|
||||
const AudioTrack = require('../files/AudioTrack')
|
||||
|
||||
class Audiobook {
|
||||
|
@ -93,6 +93,14 @@ class Audiobook {
|
|||
return this.audioFiles.some(af => af.embeddedCoverArt)
|
||||
}
|
||||
|
||||
setData(name, index) {
|
||||
this.id = getId('ab')
|
||||
this.name = name
|
||||
this.index = index
|
||||
this.addedAt = Date.now()
|
||||
this.updatedAt = Date.now()
|
||||
}
|
||||
|
||||
update(payload) {
|
||||
var json = this.toJSON()
|
||||
var hasUpdates = false
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const EBookFile = require('../files/EBookFile')
|
||||
const { areEquivalent, copyValue } = require('../../utils/index')
|
||||
const { areEquivalent, copyValue, getId } = require('../../utils/index')
|
||||
|
||||
class EBook {
|
||||
constructor(ebook) {
|
||||
|
@ -64,6 +64,15 @@ class EBook {
|
|||
return this.ebookFile.metadata.size
|
||||
}
|
||||
|
||||
setData(ebookFile, index) {
|
||||
this.id = getId('eb')
|
||||
this.name = ebookFile.metadata.filename
|
||||
this.index = index
|
||||
this.ebookFile = ebookFile
|
||||
this.addedAt = Date.now()
|
||||
this.updatedAt = Date.now()
|
||||
}
|
||||
|
||||
findFileWithInode(inode) {
|
||||
return this.ebookFile.ino === inode
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ const { areEquivalent, copyValue } = require('../../utils/index')
|
|||
const { parseOpfMetadataXML } = require('../../utils/parseOpfMetadata')
|
||||
const { readTextFile } = require('../../utils/fileUtils')
|
||||
|
||||
const EBookFile = require('../files/EBookFile')
|
||||
const Audiobook = require('../entities/Audiobook')
|
||||
const EBook = require('../entities/EBook')
|
||||
|
||||
|
@ -267,9 +268,30 @@ class Book {
|
|||
}
|
||||
|
||||
addEbookFile(libraryFile) {
|
||||
// var newEbook = new EBookFile()
|
||||
// newEbook.setData(libraryFile)
|
||||
// this.ebookFiles.push(newEbook)
|
||||
var ebookFile = new EBookFile()
|
||||
ebookFile.setData(libraryFile)
|
||||
|
||||
var ebookIndex = this.ebooks.length + 1
|
||||
var newEBook = new EBook()
|
||||
newEBook.setData(ebookFile, ebookIndex)
|
||||
this.ebooks.push(newEBook)
|
||||
}
|
||||
|
||||
getCreateAudiobookVariant(variant) {
|
||||
if (this.audiobooks.length) {
|
||||
var ab = this.audiobooks.find(ab => ab.name == variantName)
|
||||
if (ab) return ab
|
||||
}
|
||||
var abIndex = this.audiobooks.length + 1
|
||||
var newAb = new Audiobook()
|
||||
newAb.setData(variant, abIndex)
|
||||
this.audiobooks.push(newAb)
|
||||
return newAb
|
||||
}
|
||||
|
||||
addAudioFileToAudiobook(audioFile, variant = 'default') { // Create if none
|
||||
var audiobook = this.getCreateAudiobookVariant(variant)
|
||||
audiobook.audioFiles.push(audioFile)
|
||||
}
|
||||
}
|
||||
module.exports = Book
|
Loading…
Add table
Add a link
Reference in a new issue