epub

package
v0.3.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package epub provides EPUB metadata parsing, cover extraction, and word counting.

It parses OPF metadata directly rather than relying on third-party EPUB libraries that panic on valid EPUBs with missing optional elements. Supports EPUB 2, EPUB 3, and Calibre custom metadata.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoOPF = fmt.Errorf("no OPF path found in container.xml")

ErrNoOPF is returned when the EPUB container.xml does not reference an OPF file.

Functions

func CountWordsAndPages

func CountWordsAndPages(epubPath string, wordsPerPage int) (words int, pages int, err error)

CountWordsAndPages counts the total words across all spine content documents in the EPUB and calculates an estimated page count. Values of wordsPerPage <= 0 default to 250.

func ExtractCover

func ExtractCover(epubPath string, destPath string, quality int) error

ExtractCover extracts the cover image from an EPUB and writes it as a JPEG to destPath. Quality controls JPEG compression (1-100); values <= 0 default to 85.

Types

type Author

type Author struct {
	Name     string
	SortName string
	Role     string
}

Author represents a creator or contributor extracted from EPUB metadata.

type Metadata

type Metadata struct {
	Title       string
	SortTitle   string
	Authors     []Author
	ISBN        string
	Publisher   string
	Subjects    []string
	Description string
	Language    string
	Series      string
	SeriesIndex float64
	Edition     string
	PublishDate string
}

Metadata holds the parsed metadata extracted from an EPUB file.

func Parse

func Parse(path string) (*Metadata, error)

Parse reads an EPUB file and returns its metadata.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL