EPUB Metadata: Add workaround for bug in PocketBook firmware which causes it to fail to read series metadata if the series number is declared before the series. Fixes #1488113 [Pocketbook Series Number metadata](https://bugs.launchpad.net/calibre/+bug/1488113)

This commit is contained in:
Kovid Goyal 2015-08-25 21:34:30 +05:30
parent 2a9d8e3e81
commit 379b82cd00

View File

@ -1248,6 +1248,19 @@ class OPF(object): # {{{
if c is not None:
del a['content']
a['content'] = c
# The PocketBook requires calibre:series_index to come after
# calibre:series or it fails to read series info
# We swap attributes instead of elements, as that avoids namespace
# re-declarations
smap = {}
for child in self.metadata.xpath('./*[@name="calibre:series" or @name="calibre:series_index"]'):
smap[child.get('name')] = (child, self.metadata.index(child))
if len(smap) == 2 and smap['calibre:series'][1] > smap['calibre:series_index'][1]:
s, si = smap['calibre:series'][0], smap['calibre:series_index'][0]
def swap(attr):
t = s.get(attr, '')
s.set(attr, si.get(attr, '')), si.set(attr, t)
swap('name'), swap('content')
self.write_user_metadata()
if pretty_print_opf: