mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-14 07:49:37 +00:00
Change: scanner uses any .opf file, use description if plain text, use genres #141, Add: language book detail
This commit is contained in:
parent
3eb0dc9ac3
commit
7141f70aa5
6 changed files with 76 additions and 37 deletions
|
|
@ -502,7 +502,6 @@ class Audiobook {
|
|||
|
||||
var alreadyHasDescTxt = this.otherFiles.find(of => of.filename === 'desc.txt')
|
||||
var alreadyHasReaderTxt = this.otherFiles.find(of => of.filename === 'reader.txt')
|
||||
var alreadyHasMetadataOpf = this.otherFiles.find(of => of.filename === 'metadata.opf')
|
||||
|
||||
var newOtherFilePaths = newOtherFiles.map(f => f.path)
|
||||
this.otherFiles = this.otherFiles.filter(f => newOtherFilePaths.includes(f.path))
|
||||
|
|
@ -533,21 +532,27 @@ class Audiobook {
|
|||
hasUpdates = true
|
||||
}
|
||||
}
|
||||
var metadataOpf = newOtherFiles.find(file => file.filename === 'metadata.opf' || file.filename === 'metadata.xml')
|
||||
if (metadataOpf && (!alreadyHasMetadataOpf || forceRescan)) {
|
||||
|
||||
var metadataOpf = newOtherFiles.find(file => file.ext === '.opf' || file.filename === 'metadata.xml')
|
||||
if (metadataOpf) {
|
||||
var xmlText = await readTextFile(metadataOpf.fullPath)
|
||||
if (xmlText) {
|
||||
var opfMetadata = await parseOpfMetadataXML(xmlText)
|
||||
Logger.debug(`[Audiobook] Sync Other File ${metadataOpf.filename} parsed:`, opfMetadata)
|
||||
Logger.debug(`[Audiobook] Sync Other File "${metadataOpf.filename}" parsed:`, opfMetadata)
|
||||
if (opfMetadata) {
|
||||
const bookUpdatePayload = {}
|
||||
for (const key in opfMetadata) {
|
||||
if (opfMetadata[key] && !this.book[key]) {
|
||||
// Add genres only if genres are empty
|
||||
if (key === 'genres') {
|
||||
if (opfMetadata.genres.length && !this.book._genres.length) {
|
||||
bookUpdatePayload[key] = opfMetadata.genres
|
||||
}
|
||||
} else if (opfMetadata[key] && !this.book[key]) {
|
||||
bookUpdatePayload[key] = opfMetadata[key]
|
||||
}
|
||||
}
|
||||
if (Object.keys(bookUpdatePayload).length) {
|
||||
Logger.debug(`[Audiobook] Using data found in metadata opf/xml`, bookUpdatePayload)
|
||||
Logger.debug(`[Audiobook] Using data found in OPF "${metadataOpf.filename}"`, bookUpdatePayload)
|
||||
this.update({ book: bookUpdatePayload })
|
||||
hasUpdates = true
|
||||
}
|
||||
|
|
@ -778,15 +783,20 @@ class Audiobook {
|
|||
bookUpdatePayload.narrator = readerText
|
||||
}
|
||||
|
||||
var metadataOpf = this.otherFiles.find(file => file.filename === 'metadata.opf' || file.filename === 'metadata.xml')
|
||||
var metadataOpf = this.otherFiles.find(file => file.isOPFFile || file.filename === 'metadata.xml')
|
||||
if (metadataOpf) {
|
||||
var xmlText = await readTextFile(metadataOpf.fullPath)
|
||||
if (xmlText) {
|
||||
var opfMetadata = await parseOpfMetadataXML(xmlText)
|
||||
Logger.debug(`[Audiobook] "${this.title}" found ${metadataOpf.filename} parsed:`, opfMetadata)
|
||||
Logger.debug(`[Audiobook] "${this.title}" found "${metadataOpf.filename}" parsed:`, opfMetadata)
|
||||
if (opfMetadata) {
|
||||
for (const key in opfMetadata) {
|
||||
if (opfMetadata[key] && !this.book[key] && !bookUpdatePayload[key]) {
|
||||
// Add genres only if genres are empty
|
||||
if (key === 'genres') {
|
||||
if (opfMetadata.genres.length && !this.book._genres.length) {
|
||||
bookUpdatePayload[key] = opfMetadata.genres
|
||||
}
|
||||
} else if (opfMetadata[key] && !this.book[key] && !bookUpdatePayload[key]) {
|
||||
bookUpdatePayload[key] = opfMetadata[key]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ class AudiobookFile {
|
|||
}
|
||||
}
|
||||
|
||||
get isOPFFile() {
|
||||
return this.ext ? this.ext.toLowerCase() === '.opf' : false
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
ino: this.ino || null,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class Book {
|
|||
this.publisher = null
|
||||
this.description = null
|
||||
this.isbn = null
|
||||
this.langauge = null
|
||||
this.cover = null
|
||||
this.coverFullPath = null
|
||||
this.genres = []
|
||||
|
|
@ -38,6 +39,7 @@ class Book {
|
|||
get _author() { return this.authorFL || '' }
|
||||
get _series() { return this.series || '' }
|
||||
get _authorsList() { return this._author.split(', ') }
|
||||
get _genres() { return this.genres || [] }
|
||||
|
||||
get shouldSearchForCover() {
|
||||
if (this.authorFL !== this.lastCoverSearchAuthor || this.title !== this.lastCoverSearchTitle || !this.lastCoverSearch) return true
|
||||
|
|
@ -58,6 +60,7 @@ class Book {
|
|||
this.publisher = book.publisher
|
||||
this.description = book.description
|
||||
this.isbn = book.isbn || null
|
||||
this.language = book.language || null
|
||||
this.cover = book.cover
|
||||
this.coverFullPath = book.coverFullPath || null
|
||||
this.genres = book.genres
|
||||
|
|
@ -81,6 +84,7 @@ class Book {
|
|||
publisher: this.publisher,
|
||||
description: this.description,
|
||||
isbn: this.isbn,
|
||||
language: this.language,
|
||||
cover: this.cover,
|
||||
coverFullPath: this.coverFullPath,
|
||||
genres: this.genres,
|
||||
|
|
@ -120,6 +124,7 @@ class Book {
|
|||
this.publishYear = data.publishYear || null
|
||||
this.description = data.description || null
|
||||
this.isbn = data.isbn || null
|
||||
this.language = data.language || null
|
||||
this.cover = data.cover || null
|
||||
this.coverFullPath = data.coverFullPath || null
|
||||
this.genres = data.genres || []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue