Skip to content

Commit

Permalink
Skip EPUB navigation document
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed Mar 8, 2022
1 parent 387e416 commit 6670d41
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions x_ray_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ def extract_epub(self):
content_folder = Path(self.opf_path).parent.name
if content_folder:
self.content_folder = content_folder
elif self.extract_folder.joinpath('OEBPS').is_dir():
self.content_folder = 'OEBPS'
elif self.extract_folder.joinpath('epub').is_dir():
self.content_folder = 'epub'
else:
for folder in ['OEBPS', 'epub']:
if self.extract_folder.joinpath(folder).is_dir():
self.content_folder = folder
with self.extract_folder.joinpath(self.opf_path).open('rb') as opf:
self.opf_root = etree.fromstring(opf.read())
item_path = 'opf:manifest/opf:item' \
'[@media-type="application/xhtml+xml"]'
for item in self.opf_root.findall(item_path, NAMESPACES):
if item.get('properties') == 'nav':
continue
xhtml = item.get("href")
xhtml_folder = Path(xhtml).parent.name
if xhtml_folder and xhtml_folder != self.xhtml_folder \
Expand Down

0 comments on commit 6670d41

Please sign in to comment.