diff --git a/src/calibre/devices/apple/driver.py b/src/calibre/devices/apple/driver.py index 5a0496e863..aaa9382612 100644 --- a/src/calibre/devices/apple/driver.py +++ b/src/calibre/devices/apple/driver.py @@ -2517,28 +2517,25 @@ class ITUNES(DriverBase): opf = [x for x in fnames if '.opf' in x][0] if opf: opf_tree = etree.fromstring(zf_opf.read(opf)) - ns_map = opf_tree.nsmap.keys() - for item in ns_map: - ns = opf_tree.nsmap[item] - md_el = opf_tree.find(".//{%s}metadata" % ns) - if md_el is not None: - ts = md_el.find('.//{%s}meta[@name="calibre:timestamp"]') - if ts: - timestamp = ts.get('content') - old_ts = parse_date(timestamp) - metadata.timestamp = datetime.datetime(old_ts.year, old_ts.month, old_ts.day, old_ts.hour, - old_ts.minute, old_ts.second, old_ts.microsecond+1, old_ts.tzinfo) - else: - metadata.timestamp = now() - if DEBUG: - self.log.info(" add timestamp: %s" % metadata.timestamp) - break + md_els = opf_tree.xpath('.//*[local-name()="metadata"]') + if md_els: + ts = md_els[0].find('.//*[@name="calibre:timestamp"]') + if ts is not None: + timestamp = ts.get('content') + old_ts = parse_date(timestamp) + metadata.timestamp = datetime.datetime(old_ts.year, old_ts.month, old_ts.day, old_ts.hour, + old_ts.minute, old_ts.second, old_ts.microsecond+1, old_ts.tzinfo) + if DEBUG: + self.log.info(" existing timestamp: %s" % metadata.timestamp) + else: + metadata.timestamp = now() + if DEBUG: + self.log.info(" add timestamp: %s" % metadata.timestamp) else: metadata.timestamp = now() if DEBUG: self.log.warning(" missing block in OPF file") self.log.info(" add timestamp: %s" % metadata.timestamp) - # Force the language declaration for iBooks 1.1 #metadata.language = get_lang().replace('_', '-')