mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Handle epub files which contain opf files with no <metadata> tags
This commit is contained in:
parent
512d608a95
commit
72d2a7e372
@ -692,21 +692,25 @@ class Container(object): # {{{
|
||||
return item
|
||||
|
||||
def format_opf(self):
|
||||
mdata = self.opf_xpath('//opf:metadata')[0]
|
||||
mdata.text = '\n '
|
||||
remove = set()
|
||||
for child in mdata:
|
||||
child.tail = '\n '
|
||||
try:
|
||||
if (child.get('name', '').startswith('calibre:') and
|
||||
child.get('content', '').strip() in {'{}', ''}):
|
||||
remove.add(child)
|
||||
except AttributeError:
|
||||
continue # Happens for XML comments
|
||||
for child in remove:
|
||||
mdata.remove(child)
|
||||
if len(mdata) > 0:
|
||||
mdata[-1].tail = '\n '
|
||||
try:
|
||||
mdata = self.opf_xpath('//opf:metadata')[0]
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
mdata.text = '\n '
|
||||
remove = set()
|
||||
for child in mdata:
|
||||
child.tail = '\n '
|
||||
try:
|
||||
if (child.get('name', '').startswith('calibre:') and
|
||||
child.get('content', '').strip() in {'{}', ''}):
|
||||
remove.add(child)
|
||||
except AttributeError:
|
||||
continue # Happens for XML comments
|
||||
for child in remove:
|
||||
mdata.remove(child)
|
||||
if len(mdata) > 0:
|
||||
mdata[-1].tail = '\n '
|
||||
# Ensure name comes before content, needed for Nooks
|
||||
for meta in self.opf_xpath('//opf:meta[@name="cover"]'):
|
||||
if 'content' in meta.attrib:
|
||||
|
Loading…
x
Reference in New Issue
Block a user