From 379b82cd00a68acad595002d4f8c3564d84a0737 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 25 Aug 2015 21:34:30 +0530 Subject: [PATCH] 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) --- src/calibre/ebooks/metadata/opf2.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index aaff457442..1d4ff3fa9a 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -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: