From 7b01cda9558362fde3667c9d74fe34bb913b5606 Mon Sep 17 00:00:00 2001 From: Mattias Carlsson Date: Sun, 19 Apr 2026 22:03:45 +0200 Subject: [PATCH] Fix bulk import: merge untagged files into single tagged group per folder --- src/lib/utils/bulk-import-scanner.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib/utils/bulk-import-scanner.ts b/src/lib/utils/bulk-import-scanner.ts index 09d50ed..9a2da4e 100644 --- a/src/lib/utils/bulk-import-scanner.ts +++ b/src/lib/utils/bulk-import-scanner.ts @@ -373,6 +373,23 @@ async function groupAudioFilesByMetadata( } } + // If there is exactly one tagged group alongside an ungrouped group, absorb + // the untagged files into the tagged group. Untagged files in the same folder + // almost certainly belong to the same book (e.g. one chapter was ripped + // without tags, or a cover/intro file carries different metadata). + // Only do this when there is a single tagged group — multiple tagged groups + // mean genuinely different books are mixed in the folder, so keep them separate. + const ungrouped = groups.get('__ungrouped_folder'); + if (ungrouped) { + const taggedKeys = Array.from(groups.keys()).filter((k) => k !== '__ungrouped_folder'); + if (taggedKeys.length === 1) { + const taggedGroup = groups.get(taggedKeys[0])!; + taggedGroup.files.push(...ungrouped.files); + taggedGroup.totalSize += ungrouped.totalSize; + groups.delete('__ungrouped_folder'); + } + } + // Build result with search terms return Array.from(groups.entries()).map(([groupingKey, group]) => { group.files.sort((a, b) => a.localeCompare(b));