fix bug when reading epubs created with mobitool (#5)

This commit is contained in:
T. von Dein
2026-01-05 11:19:48 +01:00
parent 02c99da8e9
commit 85d23c42f0
4 changed files with 53 additions and 19 deletions

View File

@@ -112,6 +112,8 @@ func (bk *Book) getSections() error {
// we have ncx points from the TOC, try those
if len(bk.Ncx.Points) > 0 {
known := map[string]int{}
for _, block := range bk.Ncx.Points {
sect := Section{
File: "OEBPS/" + block.Content.Src,
@@ -128,7 +130,13 @@ func (bk *Book) getSections() error {
}
}
sections = append(sections, sect)
if _, haveFile := known[sect.File]; !haveFile {
// sometimes epub's have many sections but they all
// point to the same file. To avoid duplicate content
// we ignore sections (thus files) we have already seen.
sections = append(sections, sect)
known[sect.File] = 1
}
}
if len(sections) < manifestcount {
@@ -189,7 +197,7 @@ func (bk *Book) readSectionContent() error {
ct := Content{Src: section.File, Title: section.Title}
if types.MatchString(section.MediaType) {
if err := ct.String(content); err != nil {
if err := ct.Extract(content); err != nil {
return err
}
}