From dc0899ff618570ef2b14ff1f672031b5f529d714 Mon Sep 17 00:00:00 2001 From: nickwolf Date: Wed, 29 Apr 2026 12:20:49 -0600 Subject: [PATCH] fix: preserve user-cleared scalar metadata fields on rescan When absMetadata (metadata.json) is the highest-priority source and a field is null, propagate that null into bookMetadata so lower-priority sources (e.g. audio file tags) cannot overwrite a value the user intentionally cleared. Previously all null values were skipped, causing cleared fields like subtitle to be repopulated from file tags on rescan. --- server/scanner/AbsMetadataFileScanner.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/scanner/AbsMetadataFileScanner.js b/server/scanner/AbsMetadataFileScanner.js index e554dfb4..94bf2d14 100644 --- a/server/scanner/AbsMetadataFileScanner.js +++ b/server/scanner/AbsMetadataFileScanner.js @@ -34,8 +34,18 @@ class AbsMetadataFileScanner { libraryScan.addLog(LogLevel.INFO, `Found metadata file "${metadataFilePath}"`) const abMetadata = abmetadataGenerator.parseJson(metadataText) || {} for (const key in abMetadata) { - // TODO: When to override with null or empty arrays? - if (abMetadata[key] === undefined || abMetadata[key] === null) continue + if (abMetadata[key] === undefined) continue + if (abMetadata[key] === null) { + // Propagate null for scalar string fields so that values intentionally cleared + // by the user are preserved when the library is rescanned. absMetadata has the + // highest metadata precedence, so a null here means the user explicitly cleared + // the field and lower-priority sources (e.g. audio file tags) should not refill it. + const clearableStringFields = ['subtitle', 'publishedYear', 'publisher', 'description', 'isbn', 'asin', 'language'] + if (clearableStringFields.includes(key)) { + bookMetadata[key] = null + } + continue + } if (key === 'authors' && !abMetadata.authors?.length) continue if (key === 'genres' && !abMetadata.genres?.length) continue if (key === 'tags' && !abMetadata.tags?.length) continue