Structure: no-heading fallback also works for short books (body threshold relative to the median page)

This commit is contained in:
Audiobook Producer
2026-10-18 13:56:40 -05:00
parent a1138b016a
commit 13e6607abe
2 changed files with 11 additions and 2 deletions
+5 -2
View File
@@ -92,8 +92,11 @@ def find_headings(units):
found.append(h)
break
if not found:
for ui, u in enumerate(units):
if len(re.sub(r"\s", "", u["text"])) >= 500:
sizes = [len(re.sub(r"\s", "", u["text"])) for u in units]
filled = sorted(n for n in sizes if n >= 20)
floor = max(40, 0.4 * filled[len(filled) // 2]) if filled else 0 # a page with 40% of the median text or more is body
for ui, n in enumerate(sizes):
if filled and n >= floor:
return [{"unit": ui, "line": -1, "title_end": 0, "number": 1, "title": "The Complete Text", "synthetic": True}]
return found