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
|
return item
|
||||||
|
|
||||||
def format_opf(self):
|
def format_opf(self):
|
||||||
mdata = self.opf_xpath('//opf:metadata')[0]
|
try:
|
||||||
mdata.text = '\n '
|
mdata = self.opf_xpath('//opf:metadata')[0]
|
||||||
remove = set()
|
except IndexError:
|
||||||
for child in mdata:
|
pass
|
||||||
child.tail = '\n '
|
else:
|
||||||
try:
|
mdata.text = '\n '
|
||||||
if (child.get('name', '').startswith('calibre:') and
|
remove = set()
|
||||||
child.get('content', '').strip() in {'{}', ''}):
|
for child in mdata:
|
||||||
remove.add(child)
|
child.tail = '\n '
|
||||||
except AttributeError:
|
try:
|
||||||
continue # Happens for XML comments
|
if (child.get('name', '').startswith('calibre:') and
|
||||||
for child in remove:
|
child.get('content', '').strip() in {'{}', ''}):
|
||||||
mdata.remove(child)
|
remove.add(child)
|
||||||
if len(mdata) > 0:
|
except AttributeError:
|
||||||
mdata[-1].tail = '\n '
|
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
|
# Ensure name comes before content, needed for Nooks
|
||||||
for meta in self.opf_xpath('//opf:meta[@name="cover"]'):
|
for meta in self.opf_xpath('//opf:meta[@name="cover"]'):
|
||||||
if 'content' in meta.attrib:
|
if 'content' in meta.attrib:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user