From 6e621ecce163247b395f7af4bcbc0ca6250c174a Mon Sep 17 00:00:00 2001 From: Igor Kaldowski Date: Sat, 4 Dec 2021 21:07:31 +0000 Subject: [PATCH 1/4] Get series info from opf --- server/utils/index.js | 6 ++++++ server/utils/parseOpfMetadata.js | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/server/utils/index.js b/server/utils/index.js index 79b6a93a..ff7db7a2 100644 --- a/server/utils/index.js +++ b/server/utils/index.js @@ -56,6 +56,12 @@ const xmlToJSON = (xml) => { Logger.error(`[xmlToJSON] Error`, err) resolve(null) } else { + if (typeof results.package.metadata[0].meta != "undefined") { + results.package.metadata[0].meta = {} + for(var match of xml.matchAll(//g)) { + results.package.metadata[0].meta[match.groups['name']] = [match.groups['content']] + } + } resolve(results) } }) diff --git a/server/utils/parseOpfMetadata.js b/server/utils/parseOpfMetadata.js index 68ed4cd2..74df3e6a 100644 --- a/server/utils/parseOpfMetadata.js +++ b/server/utils/parseOpfMetadata.js @@ -69,6 +69,16 @@ function fetchLanguage(metadata) { return fetchTagString(metadata, 'dc:language') } +function fetchSeries(metadata) { + if(typeof metadata.meta == "undefined") return null + return fetchTagString(metadata.meta, "calibre:series") +} + +function fetchVolumeNumber(metadata) { + if(typeof metadata.meta == "undefined") return null + return fetchTagString(metadata.meta, "calibre:series_index") +} + module.exports.parseOpfMetadataXML = async (xml) => { var json = await xmlToJSON(xml) if (!json || !json.package || !json.package.metadata) return null @@ -89,7 +99,9 @@ module.exports.parseOpfMetadataXML = async (xml) => { isbn: fetchISBN(metadata), description: fetchDescription(metadata), genres: fetchGenres(metadata), - language: fetchLanguage(metadata) + language: fetchLanguage(metadata), + series: fetchSeries(metadata), + volumeNumber: fetchVolumeNumber(metadata) } return data } \ No newline at end of file From 670a4617526e2ab6d9e2a6683bc5b8c14526d314 Mon Sep 17 00:00:00 2001 From: Igor Kaldowski Date: Sat, 4 Dec 2021 21:07:43 +0000 Subject: [PATCH 2/4] Strip html from opf descriptions --- server/utils/parseOpfMetadata.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/utils/parseOpfMetadata.js b/server/utils/parseOpfMetadata.js index 74df3e6a..f48603de 100644 --- a/server/utils/parseOpfMetadata.js +++ b/server/utils/parseOpfMetadata.js @@ -1,4 +1,5 @@ const { xmlToJSON } = require('./index') +const { stripHtml } = require("string-strip-html") function parseCreators(metadata) { if (!metadata['dc:creator']) return null @@ -56,7 +57,7 @@ function fetchDescription(metadata) { // check if description is HTML or plain text. only plain text allowed // calibre stores < and > as < and > description = description.replace(/</g, '<').replace(/>/g, '>') - if (description.match(/|<\/?\s*[a-z-][^>]*\s*>|(\&(?:[\w\d]+|#\d+|#x[a-f\d]+);)/)) return null + if (description.match(/|<\/?\s*[a-z-][^>]*\s*>|(\&(?:[\w\d]+|#\d+|#x[a-f\d]+);)/)) return stripHtml(description).result return description } From 60aeb237979ebb07b9b72796f29aa0e7627cf8b3 Mon Sep 17 00:00:00 2001 From: Igor Kaldowski Date: Sat, 4 Dec 2021 22:10:26 +0000 Subject: [PATCH 3/4] Fix Series Sort --- server/controllers/LibraryController.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index 1650d566..dbe35425 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -179,7 +179,7 @@ class LibraryController { series = series.slice(startIndex, startIndex + payload.limit) } - payload.results = series + payload.results = sort(series).asc(s => s.name) res.json(payload) } @@ -194,7 +194,7 @@ class LibraryController { return res.status(404).send('Series not found') } audiobooks = sort(audiobooks).asc(ab => { - return ab.book.volumeNumber + return Number(ab.book.volumeNumber) }) res.json({ results: audiobooks.map(ab => ab.toJSONExpanded()), From 4ac0bd6770912d904c38ed84fe3647532e227c16 Mon Sep 17 00:00:00 2001 From: Igor Kaldowski Date: Sat, 4 Dec 2021 22:15:23 +0000 Subject: [PATCH 4/4] Moved getting xml meta entries to opf parser --- server/utils/index.js | 6 ------ server/utils/parseOpfMetadata.js | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/utils/index.js b/server/utils/index.js index ff7db7a2..79b6a93a 100644 --- a/server/utils/index.js +++ b/server/utils/index.js @@ -56,12 +56,6 @@ const xmlToJSON = (xml) => { Logger.error(`[xmlToJSON] Error`, err) resolve(null) } else { - if (typeof results.package.metadata[0].meta != "undefined") { - results.package.metadata[0].meta = {} - for(var match of xml.matchAll(//g)) { - results.package.metadata[0].meta[match.groups['name']] = [match.groups['content']] - } - } resolve(results) } }) diff --git a/server/utils/parseOpfMetadata.js b/server/utils/parseOpfMetadata.js index f48603de..83f3e3cb 100644 --- a/server/utils/parseOpfMetadata.js +++ b/server/utils/parseOpfMetadata.js @@ -90,6 +90,13 @@ module.exports.parseOpfMetadataXML = async (xml) => { metadata = metadata[0] } + if (typeof metadata.meta != "undefined") { + metadata.meta = {} + for(var match of xml.matchAll(//g)) { + metadata.meta[match.groups['name']] = [match.groups['content']] + } + } + var creators = parseCreators(metadata) var data = { title: fetchTitle(metadata),