accept epub3 from google docs

they don't set toc attribute on spine
pull/46/head
eric 2018-01-26 10:45:09 -05:00
parent ef6bfa9046
commit 560a2306dc
1 changed files with 5 additions and 2 deletions

View File

@ -141,8 +141,11 @@ class EPUB(zipfile.ZipFile):
raise InvalidEpub("Cannot process an EPUB without unique-identifier attribute of the package element")
# Get and parse the TOC
toc_id = self.opf[2].get("toc")
expr = ".//{0}item[@id='{1:s}']".format(NAMESPACE["opf"], toc_id)
toc_name = self.opf.find(expr).get("href")
if toc_id:
expr = ".//{0}item[@id='{1:s}']".format(NAMESPACE["opf"], toc_id)
else:
expr = ".//{0}item[@properties='nav']".format(NAMESPACE["opf"])
toc_name = self.opf.find(expr).get("href")
self.ncx_path = os.path.join(self.root_folder, toc_name)
self.ncx = ET.fromstring(self.read(self.ncx_path))
self.contents = [{"name": i[0][0].text or "None", # Build a list of toc elements