mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Merge pull request #3170 from ajvgwu/nfo-metadata-language
Parse book language from NFO metadata source
This commit is contained in:
commit
c0fd24770e
@ -2,24 +2,26 @@ const { parseNfoMetadata } = require('../utils/parsers/parseNfoMetadata')
|
|||||||
const { readTextFile } = require('../utils/fileUtils')
|
const { readTextFile } = require('../utils/fileUtils')
|
||||||
|
|
||||||
class NfoFileScanner {
|
class NfoFileScanner {
|
||||||
constructor() { }
|
constructor() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse metadata from .nfo file found in library scan and update bookMetadata
|
* Parse metadata from .nfo file found in library scan and update bookMetadata
|
||||||
*
|
*
|
||||||
* @param {import('../models/LibraryItem').LibraryFileObject} nfoLibraryFileObj
|
* @param {import('../models/LibraryItem').LibraryFileObject} nfoLibraryFileObj
|
||||||
* @param {Object} bookMetadata
|
* @param {Object} bookMetadata
|
||||||
*/
|
*/
|
||||||
async scanBookNfoFile(nfoLibraryFileObj, bookMetadata) {
|
async scanBookNfoFile(nfoLibraryFileObj, bookMetadata) {
|
||||||
const nfoText = await readTextFile(nfoLibraryFileObj.metadata.path)
|
const nfoText = await readTextFile(nfoLibraryFileObj.metadata.path)
|
||||||
const nfoMetadata = nfoText ? await parseNfoMetadata(nfoText) : null
|
const nfoMetadata = nfoText ? await parseNfoMetadata(nfoText) : null
|
||||||
if (nfoMetadata) {
|
if (nfoMetadata) {
|
||||||
for (const key in nfoMetadata) {
|
for (const key in nfoMetadata) {
|
||||||
if (key === 'tags') { // Add tags only if tags are empty
|
if (key === 'tags') {
|
||||||
|
// Add tags only if tags are empty
|
||||||
if (nfoMetadata.tags.length) {
|
if (nfoMetadata.tags.length) {
|
||||||
bookMetadata.tags = nfoMetadata.tags
|
bookMetadata.tags = nfoMetadata.tags
|
||||||
}
|
}
|
||||||
} else if (key === 'genres') { // Add genres only if genres are empty
|
} else if (key === 'genres') {
|
||||||
|
// Add genres only if genres are empty
|
||||||
if (nfoMetadata.genres.length) {
|
if (nfoMetadata.genres.length) {
|
||||||
bookMetadata.genres = nfoMetadata.genres
|
bookMetadata.genres = nfoMetadata.genres
|
||||||
}
|
}
|
||||||
@ -33,10 +35,12 @@ class NfoFileScanner {
|
|||||||
}
|
}
|
||||||
} else if (key === 'series') {
|
} else if (key === 'series') {
|
||||||
if (nfoMetadata.series) {
|
if (nfoMetadata.series) {
|
||||||
bookMetadata.series = [{
|
bookMetadata.series = [
|
||||||
name: nfoMetadata.series,
|
{
|
||||||
sequence: nfoMetadata.sequence || null
|
name: nfoMetadata.series,
|
||||||
}]
|
sequence: nfoMetadata.sequence || null
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
} else if (nfoMetadata[key] && key !== 'sequence') {
|
} else if (nfoMetadata[key] && key !== 'sequence') {
|
||||||
bookMetadata[key] = nfoMetadata[key]
|
bookMetadata[key] = nfoMetadata[key]
|
||||||
@ -45,4 +49,4 @@ class NfoFileScanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = new NfoFileScanner()
|
module.exports = new NfoFileScanner()
|
||||||
|
@ -81,6 +81,10 @@ function parseNfoMetadata(nfoText) {
|
|||||||
case 'isbn-13':
|
case 'isbn-13':
|
||||||
metadata.isbn = value
|
metadata.isbn = value
|
||||||
break
|
break
|
||||||
|
case 'language':
|
||||||
|
case 'lang':
|
||||||
|
metadata.language = value
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -103,6 +103,16 @@ describe('parseNfoMetadata', () => {
|
|||||||
expect(result.asin).to.equal('B08X5JZJLH')
|
expect(result.asin).to.equal('B08X5JZJLH')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('parses language', () => {
|
||||||
|
const nfoText = 'Language: eng'
|
||||||
|
const result = parseNfoMetadata(nfoText)
|
||||||
|
expect(result.language).to.equal('eng')
|
||||||
|
|
||||||
|
const nfoText2 = 'lang: deu'
|
||||||
|
const result2 = parseNfoMetadata(nfoText2)
|
||||||
|
expect(result2.language).to.equal('deu')
|
||||||
|
})
|
||||||
|
|
||||||
it('parses description', () => {
|
it('parses description', () => {
|
||||||
const nfoText = 'Book Description\n=========\nThis is a book.\n It\'s good'
|
const nfoText = 'Book Description\n=========\nThis is a book.\n It\'s good'
|
||||||
const result = parseNfoMetadata(nfoText)
|
const result = parseNfoMetadata(nfoText)
|
||||||
|
Loading…
Reference in New Issue
Block a user