mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Update:OPF parser return array of authors and narrators without attempting to parse names #907
This commit is contained in:
parent
d15120eb5f
commit
1ad9ea92b6
@ -276,13 +276,18 @@ class Book {
|
|||||||
if (opfMetadata.genres.length && (!this.metadata.genres.length || opfMetadataOverrideDetails)) {
|
if (opfMetadata.genres.length && (!this.metadata.genres.length || opfMetadataOverrideDetails)) {
|
||||||
metadataUpdatePayload[key] = opfMetadata.genres
|
metadataUpdatePayload[key] = opfMetadata.genres
|
||||||
}
|
}
|
||||||
} else if (key === 'author') {
|
} else if (key === 'authors') {
|
||||||
if (opfMetadata.author && (!this.metadata.authors.length || opfMetadataOverrideDetails)) {
|
if (opfMetadata.authors && opfMetadata.authors.length && (!this.metadata.authors.length || opfMetadataOverrideDetails)) {
|
||||||
metadataUpdatePayload.authors = this.metadata.parseAuthorsTag(opfMetadata.author)
|
metadataUpdatePayload.authors = opfMetadata.authors.map(authorName => {
|
||||||
|
return {
|
||||||
|
id: `new-${Math.floor(Math.random() * 1000000)}`,
|
||||||
|
name: authorName
|
||||||
}
|
}
|
||||||
} else if (key === 'narrator') {
|
})
|
||||||
if (opfMetadata.narrator && (!this.metadata.narrators.length || opfMetadataOverrideDetails)) {
|
}
|
||||||
metadataUpdatePayload.narrators = this.metadata.parseNarratorsTag(opfMetadata.narrator)
|
} else if (key === 'narrators') {
|
||||||
|
if (opfMetadata.narrators && opfMetadata.narrators.length && (!this.metadata.narrators.length || opfMetadataOverrideDetails)) {
|
||||||
|
metadataUpdatePayload.narrators = opfMetadata.narrators
|
||||||
}
|
}
|
||||||
} else if (key === 'series') {
|
} else if (key === 'series') {
|
||||||
if (opfMetadata.series && (!this.metadata.series.length || opfMetadataOverrideDetails)) {
|
if (opfMetadata.series && (!this.metadata.series.length || opfMetadataOverrideDetails)) {
|
||||||
|
@ -15,10 +15,9 @@ function parseCreators(metadata) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchCreator(creators, role) {
|
function fetchCreators(creators, role) {
|
||||||
if (!creators || !creators.length) return null
|
if (!creators || !creators.length) return null
|
||||||
var creator = creators.find(c => c.role === role)
|
return creators.filter(c => c.role === role).map(c => c.value)
|
||||||
return creator ? creator.value : null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchTagString(metadata, tag) {
|
function fetchTagString(metadata, tag) {
|
||||||
@ -80,11 +79,11 @@ function fetchVolumeNumber(metadataMeta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fetchNarrators(creators, metadata) {
|
function fetchNarrators(creators, metadata) {
|
||||||
var roleNrt = fetchCreator(creators, 'nrt')
|
var narrators = fetchCreators(creators, 'nrt')
|
||||||
if (typeof metadata.meta == "undefined" || roleNrt != null) return roleNrt
|
if (typeof metadata.meta == "undefined" || narrators.length) return narrators
|
||||||
try {
|
try {
|
||||||
var narratorsJSON = JSON.parse(fetchTagString(metadata.meta, "calibre:user_metadata:#narrators").replace(/"/g, '"'))
|
var narratorsJSON = JSON.parse(fetchTagString(metadata.meta, "calibre:user_metadata:#narrators").replace(/"/g, '"'))
|
||||||
return narratorsJSON["#value#"].join(", ")
|
return narratorsJSON["#value#"]
|
||||||
} catch {
|
} catch {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -128,11 +127,13 @@ module.exports.parseOpfMetadataXML = async (xml) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var creators = parseCreators(metadata)
|
const creators = parseCreators(metadata)
|
||||||
var data = {
|
const authors = (fetchCreators(creators, 'aut') || []).filter(au => au && au.trim())
|
||||||
|
const narrators = (fetchNarrators(creators, metadata) || []).filter(nrt => nrt && nrt.trim())
|
||||||
|
const data = {
|
||||||
title: fetchTitle(metadata),
|
title: fetchTitle(metadata),
|
||||||
author: fetchCreator(creators, 'aut'),
|
authors,
|
||||||
narrator: fetchNarrators(creators, metadata),
|
narrators,
|
||||||
publishedYear: fetchDate(metadata),
|
publishedYear: fetchDate(metadata),
|
||||||
publisher: fetchPublisher(metadata),
|
publisher: fetchPublisher(metadata),
|
||||||
isbn: fetchISBN(metadata),
|
isbn: fetchISBN(metadata),
|
||||||
|
Loading…
Reference in New Issue
Block a user