def attributes(self, node): attr = VMap() vfile = node.open() img = Image.open(vfile) info = img._getexif() vfile.close() for tag, values in info.items(): if tag in self.dateTimeTags: try: decoded = str(TAGS.get(tag, tag)) try: dt = strptime(values, "%Y:%m:%d %H:%M:%S") except ValueError: try: dt = strptime(values[:-6], "%Y-%m-%dT%H:%M:%S") except ValueError: dt = strptime(values.rstrip(' '), "%a %b %d %H:%M:%S") vt = vtime(dt.tm_year, dt.tm_mon, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec, 0) vt.thisown = False attr[decoded] = Variant(vt) except Exception as e: attr[decoded] = Variant(str(values)) else: decoded = str(TAGS.get(tag, tag)) if isinstance(values, tuple): vl = VList() for value in values: vl.push_back(Variant(value)) attr[decoded] = vl else: attr[decoded] = Variant(values) return attr
def attributes(self, node): attr = VMap() vfile = node.open() img = Image.open(vfile) info = img._getexif() vfile.close() for tag, values in info.items(): if tag in self.dateTimeTags: try: decoded = str(TAGS.get(tag, tag)) try: dt = strptime(values, "%Y:%m:%d %H:%M:%S") except ValueError: try: dt = strptime(values[:-6], "%Y-%m-%dT%H:%M:%S") except ValueError: dt = strptime(values.rstrip(' '), "%a %b %d %H:%M:%S") vt = DateTime(dt.tm_year, dt.tm_mon, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec) vt.thisown = False attr[decoded] = Variant(vt) except Exception as e: attr[decoded] = Variant(str(values)) else: decoded = str(TAGS.get(tag, tag)) if decoded == "GPSInfo": try: gpsMap = VMap() for subvalue in values: subDecoded = GPSTAGS.get(subvalue, subvalue) v = values[subvalue] if str(subDecoded) == "GPSLatitude": degree = self.toDegree(v) try: ref = gpsMap["GPSLatitudeRef"] except: ref = "" if str(ref) != "N": degree = 0 - degree gpsMap["GPSLatitudeRef"] = Variant(str(degree)) elif str(subDecoded) == "GPSLongitude": degree = self.toDegree(v) try: ref = gpsMap["GPSLongitudeRef"] except: ref = "" if str(ref) != "E": degree = 0 - degree gpsMap["GPSLongitudeRef"] = Variant( str(degree)) #Variant don't handle float.. elif type(v) == str: gpsMap[str(subDecoded)] = Variant(str(v)) elif type(v) == unicode: gpsMap[str(subDecoded)] = Variant( str(v.encode('ascii', 'replace'))) elif type(v) == tuple: vl = VList() for vv in v: if type(vv) == tuple: vl.push_back(Variant(str(vv))) gpsMap[str(subDecoded)] = vl #XXX handle gps datetime else: gpsMap[str(subDecoded)] = Variant(str(v)) attr[decoded] = gpsMap except Exception as e: pass #print "Metaexif error encoding: ", e elif isinstance(values, tuple): vl = VList() for value in values: if type(values) == unicode: vl.push_back( Variant(value.encode('ascii', 'replace'))) elif type(values) == tuple: vl.push_back(Variant(str(value))) else: vl.push_back(Variant(value)) attr[decoded] = vl else: if type(values) == unicode: attr[decoded] = Variant( values.encode('ascii', 'replace')) elif type(values) == tuple: attr[decoded] = Variant(str(values)) else: attr[decoded] = Variant(values) return attr