If TOC is missing, build a flat one from the Spine.
(book_obj)
| 133 | |
| 134 | |
| 135 | def get_fallback_toc(book_obj) -> List[TOCEntry]: |
| 136 | """ |
| 137 | If TOC is missing, build a flat one from the Spine. |
| 138 | """ |
| 139 | toc = [] |
| 140 | for item in book_obj.get_items(): |
| 141 | if item.get_type() == ebooklib.ITEM_DOCUMENT: |
| 142 | name = item.get_name() |
| 143 | # Try to guess a title from the content or ID |
| 144 | title = item.get_name().replace('.html', '').replace('.xhtml', '').replace('_', ' ').title() |
| 145 | toc.append(TOCEntry(title=title, href=name, file_href=name, anchor="")) |
| 146 | return toc |
| 147 | |
| 148 | |
| 149 | def extract_metadata_robust(book_obj) -> BookMetadata: |