From 4e329a3f8ed325bcb91478f99f39b6bee5071498 Mon Sep 17 00:00:00 2001 From: Igor Kaldowski Date: Tue, 1 Feb 2022 02:32:03 +0000 Subject: [PATCH 1/2] Fetch Narrators from opf custom column --- server/utils/parseOpfMetadata.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/utils/parseOpfMetadata.js b/server/utils/parseOpfMetadata.js index 83f3e3cb..2ff20ccf 100644 --- a/server/utils/parseOpfMetadata.js +++ b/server/utils/parseOpfMetadata.js @@ -80,6 +80,15 @@ function fetchVolumeNumber(metadata) { return fetchTagString(metadata.meta, "calibre:series_index") } +function fetchNarrators(creators, metadata) { + var roleNrt = fetchCreator(creators, 'nrt') + if(typeof metadata.meta == "undefined" || roleNrt != null) return roleNrt + var narratorsTag = fetchTagString(metadata.meta, "calibre:user_metadata:#narrators") + if(narratorsTag == null) return narratorsTag + var narratorsJSON = JSON.parse(narratorsTag.replace(/"/g,'"')) + return narratorsJSON["#value#"].join(", ") +} + module.exports.parseOpfMetadataXML = async (xml) => { var json = await xmlToJSON(xml) if (!json || !json.package || !json.package.metadata) return null @@ -101,7 +110,7 @@ module.exports.parseOpfMetadataXML = async (xml) => { var data = { title: fetchTitle(metadata), author: fetchCreator(creators, 'aut'), - narrator: fetchCreator(creators, 'nrt'), + narrator: fetchNarrators(creators, metadata), publishYear: fetchDate(metadata), publisher: fetchPublisher(metadata), isbn: fetchISBN(metadata), From 4212251c7858726ecb93ee3d26a416340f3c4eb5 Mon Sep 17 00:00:00 2001 From: Igor Kaldowski Date: Tue, 1 Feb 2022 16:50:42 +0000 Subject: [PATCH 2/2] Added try catch to opf fetchNarrators --- server/utils/parseOpfMetadata.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/utils/parseOpfMetadata.js b/server/utils/parseOpfMetadata.js index 2ff20ccf..546cfb54 100644 --- a/server/utils/parseOpfMetadata.js +++ b/server/utils/parseOpfMetadata.js @@ -83,10 +83,12 @@ function fetchVolumeNumber(metadata) { function fetchNarrators(creators, metadata) { var roleNrt = fetchCreator(creators, 'nrt') if(typeof metadata.meta == "undefined" || roleNrt != null) return roleNrt - var narratorsTag = fetchTagString(metadata.meta, "calibre:user_metadata:#narrators") - if(narratorsTag == null) return narratorsTag - var narratorsJSON = JSON.parse(narratorsTag.replace(/"/g,'"')) - return narratorsJSON["#value#"].join(", ") + try { + var narratorsJSON = JSON.parse(fetchTagString(metadata.meta, "calibre:user_metadata:#narrators").replace(/"/g,'"')) + return narratorsJSON["#value#"].join(", ") + } catch { + return null + } } module.exports.parseOpfMetadataXML = async (xml) => {