From 9a697f48db605aebd9df8595553889c8237ae44a Mon Sep 17 00:00:00 2001 From: Alex <36482251+ajvgwu@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:50:27 -0400 Subject: [PATCH 1/2] feat: parse language from NFO metadata source --- server/scanner/NfoFileScanner.js | 4 ++++ server/utils/parsers/parseNfoMetadata.js | 4 ++++ test/server/utils/parsers/parseNfoMetadata.test.js | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/server/scanner/NfoFileScanner.js b/server/scanner/NfoFileScanner.js index e450b5c3..5fb042a6 100644 --- a/server/scanner/NfoFileScanner.js +++ b/server/scanner/NfoFileScanner.js @@ -38,6 +38,10 @@ class NfoFileScanner { sequence: nfoMetadata.sequence || null }] } + } else if (key === 'language') { + if (nfoMetadata.language) { + bookMetadata.language = nfoMetadata.language + } } else if (nfoMetadata[key] && key !== 'sequence') { bookMetadata[key] = nfoMetadata[key] } diff --git a/server/utils/parsers/parseNfoMetadata.js b/server/utils/parsers/parseNfoMetadata.js index 56e9400a..6682a007 100644 --- a/server/utils/parsers/parseNfoMetadata.js +++ b/server/utils/parsers/parseNfoMetadata.js @@ -81,6 +81,10 @@ function parseNfoMetadata(nfoText) { case 'isbn-13': metadata.isbn = value break + case 'language': + case 'lang': + metadata.language = value + break } } }) diff --git a/test/server/utils/parsers/parseNfoMetadata.test.js b/test/server/utils/parsers/parseNfoMetadata.test.js index 70e6a096..9ff51fbe 100644 --- a/test/server/utils/parsers/parseNfoMetadata.test.js +++ b/test/server/utils/parsers/parseNfoMetadata.test.js @@ -103,6 +103,16 @@ describe('parseNfoMetadata', () => { 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', () => { const nfoText = 'Book Description\n=========\nThis is a book.\n It\'s good' const result = parseNfoMetadata(nfoText) From 4289fe499013ce7a906624e3245d3d9fcc83da8c Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 18 Jul 2024 16:09:40 -0500 Subject: [PATCH 2/2] Update Nfo scanner and auto-formatting --- server/scanner/NfoFileScanner.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/server/scanner/NfoFileScanner.js b/server/scanner/NfoFileScanner.js index 5fb042a6..7d5b90d6 100644 --- a/server/scanner/NfoFileScanner.js +++ b/server/scanner/NfoFileScanner.js @@ -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() \ No newline at end of file +module.exports = new NfoFileScanner()