mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-10 11:21:36 +00:00
Merge branch 'master' into mf/rssInboundManager
This commit is contained in:
commit
136265febe
4 changed files with 137 additions and 16 deletions
|
|
@ -217,7 +217,8 @@ class BookScanner {
|
||||||
} else if (key === 'series') {
|
} else if (key === 'series') {
|
||||||
// Check for series added
|
// Check for series added
|
||||||
for (const seriesObj of bookMetadata.series) {
|
for (const seriesObj of bookMetadata.series) {
|
||||||
if (!media.series.some(se => se.name === seriesObj.name)) {
|
const existingBookSeries = media.series.find(se => se.name === seriesObj.name)
|
||||||
|
if (!existingBookSeries) {
|
||||||
const existingSeries = Database.libraryFilterData[libraryItemData.libraryId].series.find(se => se.name === seriesObj.name)
|
const existingSeries = Database.libraryFilterData[libraryItemData.libraryId].series.find(se => se.name === seriesObj.name)
|
||||||
if (existingSeries) {
|
if (existingSeries) {
|
||||||
await Database.bookSeriesModel.create({
|
await Database.bookSeriesModel.create({
|
||||||
|
|
@ -238,6 +239,11 @@ class BookScanner {
|
||||||
libraryScan.addLog(LogLevel.DEBUG, `Updating book "${bookMetadata.title}" added new series "${seriesObj.name}"${seriesObj.sequence ? ` with sequence "${seriesObj.sequence}"` : ''}`)
|
libraryScan.addLog(LogLevel.DEBUG, `Updating book "${bookMetadata.title}" added new series "${seriesObj.name}"${seriesObj.sequence ? ` with sequence "${seriesObj.sequence}"` : ''}`)
|
||||||
seriesUpdated = true
|
seriesUpdated = true
|
||||||
}
|
}
|
||||||
|
} else if (seriesObj.sequence && existingBookSeries.bookSeries.sequence !== seriesObj.sequence) {
|
||||||
|
libraryScan.addLog(LogLevel.DEBUG, `Updating book "${bookMetadata.title}" series "${seriesObj.name}" sequence "${existingBookSeries.bookSeries.sequence || ''}" => "${seriesObj.sequence}"`)
|
||||||
|
seriesUpdated = true
|
||||||
|
existingBookSeries.bookSeries.sequence = seriesObj.sequence
|
||||||
|
await existingBookSeries.bookSeries.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for series removed
|
// Check for series removed
|
||||||
|
|
@ -657,7 +663,7 @@ class BookScanner {
|
||||||
if (!this.libraryItemData.metadataNfoLibraryFile) return
|
if (!this.libraryItemData.metadataNfoLibraryFile) return
|
||||||
await NfoFileScanner.scanBookNfoFile(this.libraryItemData.metadataNfoLibraryFile, this.bookMetadata)
|
await NfoFileScanner.scanBookNfoFile(this.libraryItemData.metadataNfoLibraryFile, this.bookMetadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description from desc.txt and narrator from reader.txt
|
* Description from desc.txt and narrator from reader.txt
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -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,19 @@ 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" && metadataMeta[i].$.content?.trim()) {
|
||||||
function fetchVolumeNumber(metadataMeta) {
|
const name = metadataMeta[i].$.content.trim()
|
||||||
if (!metadataMeta) return null
|
let sequence = null
|
||||||
return fetchTagString(metadataMeta, "calibre:series_index")
|
if (metadataMeta[i + 1]?.$?.name === "calibre:series_index" && metadataMeta[i + 1].$?.content?.trim()) {
|
||||||
|
sequence = metadataMeta[i + 1].$.content.trim()
|
||||||
|
}
|
||||||
|
result.push({ name, sequence })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchNarrators(creators, metadata) {
|
function fetchNarrators(creators, metadata) {
|
||||||
|
|
@ -173,8 +179,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
|
||||||
|
|
|
||||||
113
test/server/utils/parsers/parseOpfMetadata.test.js
Normal file
113
test/server/utils/parsers/parseOpfMetadata.test.js
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
const chai = require('chai')
|
||||||
|
const expect = chai.expect
|
||||||
|
const { parseOpfMetadataXML } = require('../../../../server/utils/parsers/parseOpfMetadata')
|
||||||
|
|
||||||
|
describe('parseOpfMetadata - test series', async () => {
|
||||||
|
it('test one series', 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 series - 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)
|
||||||
|
expect(parsedOpf.series).to.deep.equal([
|
||||||
|
{ "name": "Serie 1", "sequence": null },
|
||||||
|
{ "name": "Serie 2", "sequence": "abc" },
|
||||||
|
{ "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…
Add table
Add a link
Reference in a new issue