mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-24 20:59:38 +00:00
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:
parent
aa50cc2d81
commit
295c6b0c74
5 changed files with 58 additions and 6 deletions
|
|
@ -124,8 +124,8 @@ class Db {
|
|||
if (!this.serverSettings) {
|
||||
this.serverSettings = new ServerSettings()
|
||||
await this.insertEntity('settings', this.serverSettings)
|
||||
global.ServerSettings = this.serverSettings.toJSON()
|
||||
}
|
||||
global.ServerSettings = this.serverSettings.toJSON()
|
||||
}
|
||||
|
||||
async load() {
|
||||
|
|
@ -311,5 +311,12 @@ class Db {
|
|||
return []
|
||||
})
|
||||
}
|
||||
|
||||
// Check if server was updated and previous version was earlier than param
|
||||
checkPreviousVersionIsBefore(version) {
|
||||
if (!this.previousVersion) return false
|
||||
// true if version > previousVersion
|
||||
return version.localeCompare(this.previousVersion) >= 0
|
||||
}
|
||||
}
|
||||
module.exports = Db
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ class Server {
|
|||
this.Uid = isNaN(UID) ? 0 : Number(UID)
|
||||
this.Gid = isNaN(GID) ? 0 : Number(GID)
|
||||
this.Host = '0.0.0.0'
|
||||
global.Uid = this.Uid
|
||||
global.Gid = this.Gid
|
||||
global.ConfigPath = Path.normalize(CONFIG_PATH)
|
||||
global.AudiobookPath = Path.normalize(AUDIOBOOK_PATH)
|
||||
global.MetadataPath = Path.normalize(METADATA_PATH)
|
||||
|
|
@ -132,6 +134,10 @@ class Server {
|
|||
Logger.info(`[Server] Running scan for duplicate book IDs`)
|
||||
await this.scanner.fixDuplicateIds()
|
||||
}
|
||||
// If server upgrade and last version was 1.7.0 or earlier - add abmetadata files
|
||||
// if (this.db.checkPreviousVersionIsBefore('1.7.1')) {
|
||||
// TODO: wait until stable
|
||||
// }
|
||||
|
||||
if (this.db.serverSettings.scannerDisableWatcher) {
|
||||
Logger.info(`[Server] Watcher is disabled`)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -19,7 +19,7 @@ const bookKeyMap = {
|
|||
genres: 'genresCommaSeparated'
|
||||
}
|
||||
|
||||
function generate(audiobook, outputPath, uid, gid) {
|
||||
function generate(audiobook, outputPath) {
|
||||
var fileString = ';ABMETADATA1\n'
|
||||
fileString += `#audiobookshelf v${package.version}\n\n`
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ function generate(audiobook, outputPath, uid, gid) {
|
|||
}
|
||||
|
||||
return fs.writeFile(outputPath, fileString).then(() => {
|
||||
return filePerms(outputPath, 0o774, uid, gid).then(() => true)
|
||||
return filePerms(outputPath, 0o774, global.Uid, global.Gid).then(() => true)
|
||||
}).catch((error) => {
|
||||
Logger.error(`[absMetaFileGenerator] Failed to save abs file`, error)
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue