def convert_metadata(self, oeb): from lxml import etree from calibre.ebooks.oeb.base import OPF, OPF2_NS from calibre.ebooks.metadata.opf2 import OPF as ReadOPF from io import BytesIO package = etree.Element(OPF('package'), attrib={'version': '2.0'}, nsmap={None: OPF2_NS}) oeb.metadata.to_opf2(package) self.mi = ReadOPF(BytesIO(etree.tostring(package, encoding='utf-8')), populate_spine=False, try_to_guess_cover=False).to_book_metadata()
def convert_metadata(self, oeb): E = ElementMaker( namespace=namespaces['cp'], nsmap={x: namespaces[x] for x in 'cp dc dcterms xsi'.split()}) cp = E.coreProperties(E.revision("1"), E.lastModifiedBy('calibre')) ts = utcnow().isoformat(str('T')).rpartition('.')[0] + 'Z' for x in 'created modified'.split(): x = cp.makeelement( '{%s}%s' % (namespaces['dcterms'], x), **{'{%s}type' % namespaces['xsi']: 'dcterms:W3CDTF'}) x.text = ts cp.append(x) package = etree.Element(OPF('package'), attrib={'version': '2.0'}, nsmap={None: OPF2_NS}) oeb.metadata.to_opf2(package) self.mi = ReadOPF(BytesIO(xml2str(package)), populate_spine=False, try_to_guess_cover=False).to_book_metadata() update_doc_props(cp, self.mi) return xml2str(cp)