Skip to content

Instantly share code, notes, and snippets.

@ciscorn
Created September 22, 2018 03:01
Show Gist options
  • Save ciscorn/644491c9be4ae36f88185069a9abb5c2 to your computer and use it in GitHub Desktop.
Save ciscorn/644491c9be4ae36f88185069a9abb5c2 to your computer and use it in GitHub Desktop.
EPUBの見開き方向を right-to-left (縦書き用) に変える
import sys
from zipfile import ZipFile
import lxml.etree as et
for path in sys.argv[1:]:
zf = ZipFile(path, mode='a')
with zf.open('OEBPS/content.opf', mode='r') as f:
doc = et.parse(f)
spine = doc.find('.//{http://www.idpf.org/2007/opf}spine')
print(spine.get("page-progression-direction"))
spine.set("page-progression-direction", "rtl")
with zf.open('OEBPS/content.opf', mode='w') as f:
f.write(et.tostring(doc, encoding='utf-8', pretty_print=True))
zf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment