Fix bulk import: merge untagged files into single tagged group per folder

This commit is contained in:
Mattias Carlsson
2026-04-19 22:03:45 +02:00
parent 9a6062d860
commit 7b01cda955
+17
View File
@@ -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));