Update Nfo scanner and auto-formatting

This commit is contained in:
advplyr 2024-07-18 16:09:40 -05:00
parent 71cd86fdd5
commit 4289fe4990

View File

@ -2,24 +2,26 @@ const { parseNfoMetadata } = require('../utils/parsers/parseNfoMetadata')
const { readTextFile } = require('../utils/fileUtils')
class NfoFileScanner {
constructor() { }
constructor() {}
/**
* Parse metadata from .nfo file found in library scan and update bookMetadata
*
* @param {import('../models/LibraryItem').LibraryFileObject} nfoLibraryFileObj
* @param {Object} bookMetadata
*
* @param {import('../models/LibraryItem').LibraryFileObject} nfoLibraryFileObj
* @param {Object} bookMetadata
*/
async scanBookNfoFile(nfoLibraryFileObj, bookMetadata) {
const nfoText = await readTextFile(nfoLibraryFileObj.metadata.path)
const nfoMetadata = nfoText ? await parseNfoMetadata(nfoText) : null
if (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) {
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) {
bookMetadata.genres = nfoMetadata.genres
}
@ -33,14 +35,12 @@ class NfoFileScanner {
}
} else if (key === 'series') {
if (nfoMetadata.series) {
bookMetadata.series = [{
name: nfoMetadata.series,
sequence: nfoMetadata.sequence || null
}]
}
} else if (key === 'language') {
if (nfoMetadata.language) {
bookMetadata.language = nfoMetadata.language
bookMetadata.series = [
{
name: nfoMetadata.series,
sequence: nfoMetadata.sequence || null
}
]
}
} else if (nfoMetadata[key] && key !== 'sequence') {
bookMetadata[key] = nfoMetadata[key]
@ -49,4 +49,4 @@ class NfoFileScanner {
}
}
}
module.exports = new NfoFileScanner()
module.exports = new NfoFileScanner()