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] 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)