Add:Generate book metadata file when book details are changed,Add:Server setting for storing book metadata in book folder

This commit is contained in:
advplyr 2022-02-27 14:28:18 -06:00
parent aa50cc2d81
commit 295c6b0c74
5 changed files with 58 additions and 6 deletions

View file

@ -5,6 +5,7 @@ const { comparePaths, getIno, getId, elapsedPretty } = require('../utils/index')
const { parseOpfMetadataXML } = require('../utils/parseOpfMetadata')
const { extractCoverArt } = require('../utils/ffmpegHelpers')
const nfoGenerator = require('../utils/nfoGenerator')
const abmetadataGenerator = require('../utils/abmetadataGenerator')
const Logger = require('../Logger')
const Book = require('./Book')
const AudioTrack = require('./AudioTrack')
@ -44,6 +45,9 @@ class Audiobook {
if (audiobook) {
this.construct(audiobook)
}
// Temp flags
this.isSavingMetadata = false
}
construct(audiobook) {
@ -424,6 +428,10 @@ class Audiobook {
if (payload.book && this.book.update(payload.book)) {
hasUpdates = true
// TODO: Book may have updates where this save is not necessary
// add check first if metadata update is needed
this.saveAbMetadata()
}
if (hasUpdates) {
@ -1025,5 +1033,25 @@ class Audiobook {
}
return false
}
async saveAbMetadata() {
if (this.isSavingMetadata) return
this.isSavingMetadata = true
var metadataPath = Path.join(global.MetadataPath, 'books', this.id)
if (global.ServerSettings.storeMetadataWithBook) {
metadataPath = this.fullPath
} else {
// Make sure metadata book dir exists
await fs.ensureDir(metadataPath)
}
metadataPath = Path.join(metadataPath, 'metadata.abs')
return abmetadataGenerator.generate(this, metadataPath).then((success) => {
if (!success) Logger.error(`[Audiobook] Failed saving abmetadata to "${metadataPath}"`)
else Logger.debug(`[Audiobook] Success saving abmetadata to "${metadataPath}"`)
return success
})
}
}
module.exports = Audiobook