mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Add: OPF file supports multiple series as sequence of : calibre:series and calibre:series_index; including tests
This commit is contained in:
parent
68d36522b1
commit
cd7c4baaaf
@ -32,11 +32,8 @@ class OpfFileScanner {
|
|||||||
bookMetadata.narrators = opfMetadata.narrators
|
bookMetadata.narrators = opfMetadata.narrators
|
||||||
}
|
}
|
||||||
} else if (key === 'series') {
|
} else if (key === 'series') {
|
||||||
if (opfMetadata.series) {
|
if (opfMetadata.series?.length) {
|
||||||
bookMetadata.series = [{
|
bookMetadata.series = opfMetadata.series
|
||||||
name: opfMetadata.series,
|
|
||||||
sequence: opfMetadata.sequence || null
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
} else if (opfMetadata[key] && key !== 'sequence') {
|
} else if (opfMetadata[key] && key !== 'sequence') {
|
||||||
bookMetadata[key] = opfMetadata[key]
|
bookMetadata[key] = opfMetadata[key]
|
||||||
|
@ -100,13 +100,20 @@ function fetchLanguage(metadata) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fetchSeries(metadataMeta) {
|
function fetchSeries(metadataMeta) {
|
||||||
if (!metadataMeta) return null
|
if (!metadataMeta) return []
|
||||||
return fetchTagString(metadataMeta, "calibre:series")
|
const result = []
|
||||||
}
|
for (let i = 0; i < metadataMeta.length; i++) {
|
||||||
|
if (metadataMeta[i].$.name === "calibre:series") {
|
||||||
function fetchVolumeNumber(metadataMeta) {
|
const name = metadataMeta[i].$.content
|
||||||
if (!metadataMeta) return null
|
let sequence = null
|
||||||
return fetchTagString(metadataMeta, "calibre:series_index")
|
if (i + 1 < metadataMeta.length &&
|
||||||
|
metadataMeta[i + 1].$.name === "calibre:series_index" && metadataMeta[i + 1].$.content) {
|
||||||
|
sequence = metadataMeta[i + 1].$.content
|
||||||
|
}
|
||||||
|
result.push({ name, sequence })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchNarrators(creators, metadata) {
|
function fetchNarrators(creators, metadata) {
|
||||||
@ -173,8 +180,7 @@ module.exports.parseOpfMetadataXML = async (xml) => {
|
|||||||
description: fetchDescription(metadata),
|
description: fetchDescription(metadata),
|
||||||
genres: fetchGenres(metadata),
|
genres: fetchGenres(metadata),
|
||||||
language: fetchLanguage(metadata),
|
language: fetchLanguage(metadata),
|
||||||
series: fetchSeries(metadata.meta),
|
series: fetchSeries(metadataMeta),
|
||||||
sequence: fetchVolumeNumber(metadata.meta),
|
|
||||||
tags: fetchTags(metadata)
|
tags: fetchTags(metadata)
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
85
test/server/utils/parsers/parseOpfMetadata.test.js
Normal file
85
test/server/utils/parsers/parseOpfMetadata.test.js
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
const chai = require('chai')
|
||||||
|
const expect = chai.expect
|
||||||
|
const { parseOpfMetadataXML } = require('../../../../server/utils/parsers/parseOpfMetadata')
|
||||||
|
|
||||||
|
|
||||||
|
describe('parseOpfMetadata - test series', async () => {
|
||||||
|
it('test one serie', async() => {
|
||||||
|
const opf = `
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
||||||
|
<metadata>
|
||||||
|
<meta name="calibre:series" content="Serie"/>
|
||||||
|
<meta name="calibre:series_index" content="1"/>
|
||||||
|
</metadata>
|
||||||
|
</package>
|
||||||
|
`
|
||||||
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
|
expect(parsedOpf.series).to.deep.equal([{"name": "Serie","sequence": "1"}])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('test more then 1 serie - in correct order', async() => {
|
||||||
|
const opf = `
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
||||||
|
<metadata>
|
||||||
|
<meta name="calibre:series" content="Serie 1"/>
|
||||||
|
<meta name="calibre:series_index" content="1"/>
|
||||||
|
<meta name="calibre:series" content="Serie 2"/>
|
||||||
|
<meta name="calibre:series_index" content="2"/>
|
||||||
|
<meta name="calibre:series" content="Serie 3"/>
|
||||||
|
<meta name="calibre:series_index" content="3"/>
|
||||||
|
</metadata>
|
||||||
|
</package>
|
||||||
|
`
|
||||||
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
|
expect(parsedOpf.series).to.deep.equal([
|
||||||
|
{"name": "Serie 1","sequence": "1"},
|
||||||
|
{"name": "Serie 2","sequence": "2"},
|
||||||
|
{"name": "Serie 3","sequence": "3"},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('test messed order of series content and index', async() => {
|
||||||
|
const opf = `
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
||||||
|
<metadata>
|
||||||
|
<meta name="calibre:series" content="Serie 1"/>
|
||||||
|
<meta name="calibre:series_index" content="1"/>
|
||||||
|
<meta name="calibre:series_index" content="2"/>
|
||||||
|
<meta name="calibre:series_index" content="3"/>
|
||||||
|
<meta name="calibre:series" content="Serie 3"/>
|
||||||
|
</metadata>
|
||||||
|
</package>
|
||||||
|
`
|
||||||
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
|
expect(parsedOpf.series).to.deep.equal([
|
||||||
|
{"name": "Serie 1","sequence": "1"},
|
||||||
|
{"name": "Serie 3","sequence": null},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('test different values of series content and index', async() => {
|
||||||
|
const opf = `
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
||||||
|
<metadata>
|
||||||
|
<meta name="calibre:series" content="Serie 1"/>
|
||||||
|
<meta name="calibre:series_index"/>
|
||||||
|
<meta name="calibre:series" content="Serie 2"/>
|
||||||
|
<meta name="calibre:series_index" content="abc"/>
|
||||||
|
<meta name="calibre:series" content="Serie 3"/>
|
||||||
|
<meta name="calibre:series_index" content=""/>
|
||||||
|
</metadata>
|
||||||
|
</package>
|
||||||
|
`
|
||||||
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
|
// console.log(JSON.stringify(parsedOpf, null, 4))
|
||||||
|
expect(parsedOpf.series).to.deep.equal([
|
||||||
|
{"name": "Serie 1", "sequence": null},
|
||||||
|
{"name": "Serie 2", "sequence": "abc"},
|
||||||
|
{"name": "Serie 3", "sequence": null},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user