Merge pull request #218 from igorkaldowski/master

Get more data from opf
This commit is contained in:
advplyr 2021-12-04 16:17:53 -06:00 committed by GitHub
commit 415b58e393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -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()),

View File

@ -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 &lt; and &gt;
description = description.replace(/&lt;/g, '<').replace(/&gt;/g, '>')
if (description.match(/<!DOCTYPE html>|<\/?\s*[a-z-][^>]*\s*>|(\&(?:[\w\d]+|#\d+|#x[a-f\d]+);)/)) return null
if (description.match(/<!DOCTYPE html>|<\/?\s*[a-z-][^>]*\s*>|(\&(?:[\w\d]+|#\d+|#x[a-f\d]+);)/)) return stripHtml(description).result
return description
}
@ -69,6 +70,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
@ -79,6 +90,13 @@ module.exports.parseOpfMetadataXML = async (xml) => {
metadata = metadata[0]
}
if (typeof metadata.meta != "undefined") {
metadata.meta = {}
for(var match of xml.matchAll(/<meta name="(?<name>.+)" content="(?<content>.+)"\/>/g)) {
metadata.meta[match.groups['name']] = [match.groups['content']]
}
}
var creators = parseCreators(metadata)
var data = {
title: fetchTitle(metadata),
@ -89,7 +107,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
}