From 81d70b68d9a725653d73a89d175bdf30931f09f3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 27 Jul 2009 12:06:16 -0600 Subject: [PATCH] EPUB Output: Fix generated OPF to be compatible with the asinine epubchecker. Also fix bug that was causing the default cover to use the date even when authors are present. --- src/calibre/ebooks/epub/output.py | 6 ++++-- src/calibre/ebooks/oeb/base.py | 1 - src/calibre/ebooks/oeb/output.py | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/epub/output.py b/src/calibre/ebooks/epub/output.py index 9280aec85c..18009a9a9f 100644 --- a/src/calibre/ebooks/epub/output.py +++ b/src/calibre/ebooks/epub/output.py @@ -125,7 +125,9 @@ class EPUBOutput(OutputFormatPlugin):

%(title)s

- +
+ +

%(author)s

Produced by %(app)s

@@ -196,7 +198,7 @@ class EPUBOutput(OutputFormatPlugin): images_rc m = self.oeb.metadata title = unicode(m.title[0]) - a = [unicode(x) for x in m.creators if m.role == 'aut'] + a = [unicode(x) for x in m.creator if x.role == 'aut'] author = authors_to_string(a) if QApplication.instance() is None: QApplication([]) f = QFile(':/library') diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index 1f2df923dc..8941f97304 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -694,7 +694,6 @@ class Metadata(object): def to_opf2(self, parent=None): nsmap = self._opf2_nsmap nsrmap = dict((value, key) for key, value in nsmap.items()) - nsmap.pop('opf', '') elem = element(parent, OPF('metadata'), nsmap=nsmap) for term in self.items: for item in self.items[term]: diff --git a/src/calibre/ebooks/oeb/output.py b/src/calibre/ebooks/oeb/output.py index 4df8c0f679..123d485b00 100644 --- a/src/calibre/ebooks/oeb/output.py +++ b/src/calibre/ebooks/oeb/output.py @@ -3,7 +3,7 @@ __license__ = 'GPL 3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os +import os, re from lxml import etree @@ -34,6 +34,10 @@ class OEBOutput(OutputFormatPlugin): if root is not None: raw = etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=True) + if key == OPF_MIME: + # Needed as I can't get lxml to output opf:role and + # not output as well + raw = re.sub(r'(<[/]{0,1})opf:', r'\1', raw) with open(href, 'wb') as f: f.write(raw)