Compare commits

...

3 commits

Author SHA1 Message Date
e656432802 Add command 'setcover'. 2026-07-04 22:56:13 -07:00
43d5195367 Add command 'manifest'. 2026-07-04 22:55:41 -07:00
8608ffaf75 Dismiss HTML vs XML parser warning. 2026-07-04 22:47:01 -07:00

View file

@ -14,6 +14,7 @@ import tempfile
import tinycss2
import urllib.parse
import uuid
import warnings
import zipfile
from voussoirkit import betterhelp
@ -24,6 +25,8 @@ from voussoirkit import vlogging
log = vlogging.get_logger(__name__, 'epubfile')
warnings.filterwarnings("ignore", category=bs4.XMLParsedAsHTMLWarning)
HTML_LINK_PROPERTIES = {
'a': ['href'],
'audio': ['src'],
@ -1503,6 +1506,12 @@ def holdit_argparse(args):
pipeable.stdout(epub.absolute_path)
return 0
def manifest_argparse(args):
book = Epub(args.epub)
for item in book.get_manifest_items(soup=True):
pipeable.stdout(str(item))
return 0
def merge(
input_filepaths,
demote_headers=False,
@ -1618,6 +1627,11 @@ def normalize_argparse(args):
pipeable.stdout(epub.absolute_path)
return 0
def setcover_argparse(args):
book = Epub(args.epub)
book.set_cover_image(args.cover_id)
return 0
def setfont(book, new_font, autoyes=False):
css_id = 'epubfile_setfont'
css_basename = 'epubfile_setfont.css'
@ -1811,6 +1825,19 @@ def main(argv):
################################################################################################
p_manifest = subparsers.add_parser(
'manifest',
description='''
Print all of the manifest entries in the book.
''',
)
p_manifest.add_argument(
'epub',
)
p_manifest.set_defaults(func=manifest_argparse)
################################################################################################
p_merge = subparsers.add_parser(
'merge',
description='''
@ -1905,6 +1932,24 @@ def main(argv):
################################################################################################
p_setcover = subparsers.add_parser(
'setcover',
description='''
Set the book's cover image to the specified manifest ID.
You can use the manifest command first to see what's in the book.
''',
)
p_setcover.add_argument(
'epub',
)
p_setcover.add_argument(
'cover_id',
)
p_setcover.set_defaults(func=setcover_argparse)
################################################################################################
p_setfont = subparsers.add_parser(
'setfont',
description='''