mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Update opf parser to ignore series with empty content and add tests
This commit is contained in:
parent
cd7c4baaaf
commit
6de0465b86
@ -103,12 +103,11 @@ function fetchSeries(metadataMeta) {
|
|||||||
if (!metadataMeta) return []
|
if (!metadataMeta) return []
|
||||||
const result = []
|
const result = []
|
||||||
for (let i = 0; i < metadataMeta.length; i++) {
|
for (let i = 0; i < metadataMeta.length; i++) {
|
||||||
if (metadataMeta[i].$.name === "calibre:series") {
|
if (metadataMeta[i].$?.name === "calibre:series" && metadataMeta[i].$.content?.trim()) {
|
||||||
const name = metadataMeta[i].$.content
|
const name = metadataMeta[i].$.content.trim()
|
||||||
let sequence = null
|
let sequence = null
|
||||||
if (i + 1 < metadataMeta.length &&
|
if (metadataMeta[i + 1]?.$?.name === "calibre:series_index" && metadataMeta[i + 1].$?.content?.trim()) {
|
||||||
metadataMeta[i + 1].$.name === "calibre:series_index" && metadataMeta[i + 1].$.content) {
|
sequence = metadataMeta[i + 1].$.content.trim()
|
||||||
sequence = metadataMeta[i + 1].$.content
|
|
||||||
}
|
}
|
||||||
result.push({ name, sequence })
|
result.push({ name, sequence })
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@ const chai = require('chai')
|
|||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const { parseOpfMetadataXML } = require('../../../../server/utils/parsers/parseOpfMetadata')
|
const { parseOpfMetadataXML } = require('../../../../server/utils/parsers/parseOpfMetadata')
|
||||||
|
|
||||||
|
describe('parseOpfMetadata - test series', async () => {
|
||||||
describe('parseOpfMetadata - test series', async () => {
|
it('test one series', async () => {
|
||||||
it('test one serie', async() => {
|
|
||||||
const opf = `
|
const opf = `
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?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">
|
<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">
|
||||||
@ -15,10 +14,10 @@ describe('parseOpfMetadata - test series', async () => {
|
|||||||
</package>
|
</package>
|
||||||
`
|
`
|
||||||
const parsedOpf = await parseOpfMetadataXML(opf)
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
expect(parsedOpf.series).to.deep.equal([{"name": "Serie","sequence": "1"}])
|
expect(parsedOpf.series).to.deep.equal([{ "name": "Serie", "sequence": "1" }])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('test more then 1 serie - in correct order', async() => {
|
it('test more then 1 series - in correct order', async () => {
|
||||||
const opf = `
|
const opf = `
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?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">
|
<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">
|
||||||
@ -34,13 +33,13 @@ describe('parseOpfMetadata - test series', async () => {
|
|||||||
`
|
`
|
||||||
const parsedOpf = await parseOpfMetadataXML(opf)
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
expect(parsedOpf.series).to.deep.equal([
|
expect(parsedOpf.series).to.deep.equal([
|
||||||
{"name": "Serie 1","sequence": "1"},
|
{ "name": "Serie 1", "sequence": "1" },
|
||||||
{"name": "Serie 2","sequence": "2"},
|
{ "name": "Serie 2", "sequence": "2" },
|
||||||
{"name": "Serie 3","sequence": "3"},
|
{ "name": "Serie 3", "sequence": "3" },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('test messed order of series content and index', async() => {
|
it('test messed order of series content and index', async () => {
|
||||||
const opf = `
|
const opf = `
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?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">
|
<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">
|
||||||
@ -55,12 +54,12 @@ describe('parseOpfMetadata - test series', async () => {
|
|||||||
`
|
`
|
||||||
const parsedOpf = await parseOpfMetadataXML(opf)
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
expect(parsedOpf.series).to.deep.equal([
|
expect(parsedOpf.series).to.deep.equal([
|
||||||
{"name": "Serie 1","sequence": "1"},
|
{ "name": "Serie 1", "sequence": "1" },
|
||||||
{"name": "Serie 3","sequence": null},
|
{ "name": "Serie 3", "sequence": null },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('test different values of series content and index', async() => {
|
it('test different values of series content and index', async () => {
|
||||||
const opf = `
|
const opf = `
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?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">
|
<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">
|
||||||
@ -75,11 +74,40 @@ describe('parseOpfMetadata - test series', async () => {
|
|||||||
</package>
|
</package>
|
||||||
`
|
`
|
||||||
const parsedOpf = await parseOpfMetadataXML(opf)
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
// console.log(JSON.stringify(parsedOpf, null, 4))
|
|
||||||
expect(parsedOpf.series).to.deep.equal([
|
expect(parsedOpf.series).to.deep.equal([
|
||||||
{"name": "Serie 1", "sequence": null},
|
{ "name": "Serie 1", "sequence": null },
|
||||||
{"name": "Serie 2", "sequence": "abc"},
|
{ "name": "Serie 2", "sequence": "abc" },
|
||||||
{"name": "Serie 3", "sequence": null},
|
{ "name": "Serie 3", "sequence": null },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('test empty series content', 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=""/>
|
||||||
|
<meta name="calibre:series_index" content=""/>
|
||||||
|
</metadata>
|
||||||
|
</package>
|
||||||
|
`
|
||||||
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
|
expect(parsedOpf.series).to.deep.equal([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('test series and index using an xml namespace', async () => {
|
||||||
|
const opf = `
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<ns0: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">
|
||||||
|
<ns0:metadata>
|
||||||
|
<ns0:meta name="calibre:series" content="Serie 1"/>
|
||||||
|
<ns0:meta name="calibre:series_index" content=""/>
|
||||||
|
</ns0:metadata>
|
||||||
|
</ns0:package>
|
||||||
|
`
|
||||||
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
||||||
|
expect(parsedOpf.series).to.deep.equal([
|
||||||
|
{ "name": "Serie 1", "sequence": null }
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user