def __init__(self, data, keyword_map, face_map, key): self.data = data self.key = key self._caption = sysutils.nn_string(data.get("Caption")).strip() self.comment = sysutils.nn_string(data.get("Comment")).strip() if data.has_key("DateAsTimerInterval"): self.date = applexml.getappletime(data.get("DateAsTimerInterval")) else: self.date = None self.mod_date = applexml.getappletime( data.get("ModDateAsTimerInterval")) self.image_path = data.get("ImagePath") if data.has_key("Rating"): self.rating = int(data.get("Rating")) else: self.rating = None if data.get("longitude"): latitude = float(data.get("latitude")) longitude = float(data.get("longitude")) self.gps = imageutils.GpsLocation(latitude, longitude) else: self.gps = None self.keywords = [] keyword_list = data.get("Keywords") if keyword_list is not None: for i in keyword_list: self.keywords.append(keyword_map.get(i)) self.originalpath = data.get("OriginalPath") self.roll = data.get("Roll") self.albums = [] # list of albums that this image belongs to self.faces = [] self.face_rectangles = [] self.event_name = '' # name of event (roll) that this image belongs to self.event_index = '' # index within event self.event_index0 = '' # index with event, left padded with 0 face_list = data.get("Faces") if face_list: for face_entry in face_list: face_key = face_entry.get("face key") face_name = face_map.get(face_key) if face_name: self.faces.append(face_name) # Rectangle is '{{x, y}, {width, height}}' as ratios, # referencing the lower left corner of the face rectangle. self.face_rectangles.append(parse_face_rectangle( face_entry.get("rectangle")))
def __init__(self, data, keyword_map, face_map): self.data = data self._caption = sysutils.nn_string(data.get("Caption")).strip() self.comment = sysutils.nn_string(data.get("Comment")).strip() if data.has_key("DateAsTimerInterval"): self.date = applexml.getappletime(data.get("DateAsTimerInterval")) else: self.date = None self.mod_date = applexml.getappletime( data.get("ModDateAsTimerInterval")) self.image_path = data.get("ImagePath") if data.has_key("Rating"): self.rating = int(data.get("Rating")) else: self.rating = None if data.get("longitude"): latitude = float(data.get("latitude")) longitude = float(data.get("longitude")) self.gps = imageutils.GpsLocation(latitude, longitude) else: self.gps = None self.keywords = [] keyword_list = data.get("Keywords") if keyword_list is not None: for i in keyword_list: self.keywords.append(keyword_map.get(i)) self.originalpath = data.get("OriginalPath") self.roll = data.get("Roll") self.albums = [] # list of albums that this image belongs to self.faces = [] self.face_rectangles = [] self.event_name = '' # name of event (roll) that this image belongs to self.event_index = '' # index within event self.event_index0 = '' # index with event, left padded with 0 face_list = data.get("Faces") if face_list: for face_entry in face_list: face_key = face_entry.get("face key") face_name = face_map.get(face_key) if face_name: self.faces.append(face_name) # Rectangle is '{{x, y}, {width, height}}' as ratios, # referencing the lower left corner of the face rectangle. self.face_rectangles.append( parse_face_rectangle(face_entry.get("rectangle")))
def __init__(self, data, images): IPhotoContainer.__init__( self, data.get("RollName") if data.has_key("RollName") else data.get("AlbumName"), "Event", data, images) self.albumid = data.get("RollID") if not self.albumid: self.albumid = data.get("AlbumId") self.date = applexml.getappletime( self.data.get("RollDateAsTimerInterval")) if not self.date: self.date = applexml.getappletime( self.data.get('ProjectEarliestDateAsTimerInterval')) i = 1 index_digits = len(str(len(self.images))) for image in self.images: image.event_name = self.name image.event_index = i image.event_index0 = str(i).zfill(index_digits) i += 1
def __init__(self, data, images): IPhotoContainer.__init__(self, data.get("RollName") if data.has_key("RollName") else data.get("AlbumName"), "Event", data, images) self.albumid = data.get("RollID") if not self.albumid: self.albumid = data.get("AlbumId") self.date = applexml.getappletime(self.data.get( "RollDateAsTimerInterval")) if not self.date: self.date = applexml.getappletime(self.data.get( 'ProjectEarliestDateAsTimerInterval')) i = 1 index_digits = len(str(len(self.images))) for image in self.images: image.event_name = self.name image.event_index = i image.event_index0 = str(i).zfill(index_digits) i += 1
def __init__(self, name, albumtype, data, images, ratings, aperture_data=None, verbose=False): self.name = name self._date = None self.uuid = None self.comment = None if data: if data.get("RollDateAsTimerInterval"): self._date = applexml.getappletime(data.get("RollDateAsTimerInterval")) if data.get("uuid"): self.uuid = data.get("uuid") if self.uuid == 'lastImportAlbum': albumtype = "Special Roll" if 'Comments' in data: self.comment = data.get("Comments") if aperture_data: container = None if self.uuid and self.uuid in aperture_data.folders: container = aperture_data.folders[self.uuid] elif self.uuid and self.uuid in aperture_data.albums: container = aperture_data.albums[self.uuid] if container and container.note: self.comment = container.note # The iPhoto master album has no album type. if not albumtype and data and data.has_key("Master"): albumtype = 'Master' # Convert Aperture numeric album types to iPhoto album type names. if albumtype in _APERTURE_ALBUM_TYPES: albumtype = _APERTURE_ALBUM_TYPES[albumtype] elif not albumtype: if verbose: su.pout(u'No album type for %s.' % name) elif albumtype.isdigit(): albumid = int(albumtype) if albumid > 90: # 94 - Photos # 95 - Flagged # 96 - Library Album # 97 - Projects # 98 - Aperture # 99 - Aperture Library albumtype = name else: print 'Unknown album type %s for %s.' % (albumtype, name) self.albumtype = albumtype self.data = data self.albumid = -1 self.images = [] self.albums = [] self.master = False hidden = 0 if not self.isfolder() and data and ( data.has_key("KeyList") or data.has_key("KeyListString")): keylist = data.get("KeyList") if data.has_key("KeyList") else data.get( "KeyListString").split(",") for key in keylist: if not key: continue image = images.get(key) if image: if ratings and not image.rating in ratings: continue self.images.append(image) else: hidden += 1 if verbose: su.pout(u"%s: image with id %s does not exist - could be hidden." % (name, key)) if hidden: su.pout(u"%s: %d images not exported (probably hidden)." % (name, hidden)) self._assign_names()
def __init__(self, key, data, keyword_map, face_map, aperture_data): self.id = key self.data = data self._caption = su.nn_string(data.get("Caption")).strip() self.comment = su.nn_string(data.get("Comment")).strip() version = None if aperture_data: version = aperture_data.versions.get(key) if data.has_key("DateAsTimerInterval"): self.date = applexml.getappletime(data.get("DateAsTimerInterval")) elif version: self.date = version.image_date else: # Try to get the date from a the caption in "YYYYMMDD ..." format m = re.match(_CAPTION_PATTERN, self._caption) if m: year = int(m.group(1)) month = int(m.group(2)) if not month: month = 1 date = int(m.group(3)) if not date: date = 1 self.date = datetime.datetime(year, month, date) else: self.date = None self.mod_date = applexml.getappletime( data.get("ModDateAsTimerInterval")) self.image_path = data.get("ImagePath") if data.has_key("Rating"): self.rating = int(data.get("Rating")) elif version: self.rating = version.mainRating else: self.rating = None if data.get("longitude"): latitude = float(data.get("latitude")) longitude = float(data.get("longitude")) self.gps = imageutils.GpsLocation(latitude, longitude) elif version: self.gps = version.location else: self.gps = None self.keywords = [] keyword_list = data.get("Keywords") if keyword_list is not None: for i in keyword_list: self.keywords.append(keyword_map.get(i)) elif version: self.keywords = version.keywords if version: self.originalpath = None # This is just a placeholder... # Use the preview if there are adjustments. if (version.rotation or version.hasAdjustments or not su.getfileextension(version.master_image_path) in _JPG_EXTENSIONS): #if version.rotation: # su.pout(u"Rotated: %s (%d)" % (self._caption, version.rotation)) #if version.hasAdjustments: # su.pout(u"Adjustments: %s" % (self._caption)) #if not su.getfileextension(version.master_image_path) in _JPG_EXTENSIONS: # su.pout(u"Not JPEG: %s" % (self._caption)) self.originalpath = version.master_image_path if not version.imageProxy.fullSizePreviewPath: su.pout(u"No preview path for %s." % (self.caption)) else: self.image_path = version.imageProxy.fullSizePreviewPath else: self.image_path = version.master_image_path self.originalpath = None if not version.imageProxy.fullSizePreviewUpToDate: su.pout(u"%s: full size preview not up to date." % (self.caption)) else: self.originalpath = data.get("OriginalPath") self.roll = data.get("Roll") self.albums = [] # list of albums that this image belongs to self.faces = [] self.face_rectangles = [] self.event_name = '' # name of event (roll) that this image belongs to self.event_index = '' # index within event self.event_index0 = '' # index with event, left padded with 0 face_list = data.get("Faces") if face_list: for face_entry in face_list: face_key = face_entry.get("face key") face_name = face_map.get(face_key) if face_name: self.faces.append(face_name) # Rectangle is '{{x, y}, {width, height}}' as ratios, # referencing the lower left corner of the face rectangle, # with lower left corner of image as (0,0) rectangle = parse_face_rectangle(face_entry.get("rectangle")) # Convert to using center of area, relative to upper left corner of image rectangle[0] += rectangle[2] / 2.0 rectangle[1] = max(0.0, 1.0 - rectangle[1] - rectangle[3] / 2.0) self.face_rectangles.append(rectangle) # Other keys in face_entry: face index # Now sort the faces left to right. sorted_names = {} sorted_rectangles = {} for i in xrange(len(self.faces)): x = self.face_rectangles[i][0] while sorted_names.has_key(x): x += 0.00001 sorted_names[x] = self.faces[i] sorted_rectangles[x] = self.face_rectangles[i] self.faces = [sorted_names[x] for x in sorted(sorted_names.keys())] self.face_rectangles = [ sorted_rectangles[x] for x in sorted(sorted_rectangles.keys())]
def __init__(self, name, albumtype, data, images, ratings, aperture_data=None, verbose=False): self.name = name self._date = None self.uuid = None self.comment = None if data: if data.get("RollDateAsTimerInterval"): self._date = applexml.getappletime( data.get("RollDateAsTimerInterval")) if data.get("uuid"): self.uuid = data.get("uuid") if 'Comments' in data: self.comment = data.get("Comments") if aperture_data: container = None if self.uuid and self.uuid in aperture_data.folders: container = aperture_data.folders[self.uuid] elif self.uuid and self.uuid in aperture_data.albums: container = aperture_data.albums[self.uuid] if container and container.note: self.comment = container.note # The iPhoto master album has no album type. if not albumtype and data and data.has_key("Master"): albumtype = 'Master' # Convert Aperture numeric album types to iPhoto album type names. if albumtype in _APERTURE_ALBUM_TYPES: albumtype = _APERTURE_ALBUM_TYPES[albumtype] elif not albumtype: if verbose: su.pout(u'No album type for %s.' % name) elif albumtype.isdigit(): albumid = int(albumtype) if albumid > 90: # 94 - Photos # 95 - Flagged # 96 - Library Album # 97 - Projects # 98 - Aperture # 99 - Aperture Library albumtype = name else: print 'Unknown album type %s for %s.' % (albumtype, name) self.albumtype = albumtype self.data = data self.albumid = -1 self.images = [] self.albums = [] self.master = False hidden = 0 if not self.isfolder() and data and (data.has_key("KeyList") or data.has_key("KeyListString")): keylist = data.get("KeyList") if data.has_key( "KeyList") else data.get("KeyListString").split(",") for key in keylist: if not key: continue image = images.get(key) if image: if ratings and not image.rating in ratings: continue self.images.append(image) else: hidden += 1 if verbose: su.pout( u"%s: image with id %s does not exist - could be hidden." % (name, key)) if hidden: su.pout(u"%s: %d images not exported (probably hidden)." % (name, hidden)) self._assign_names()
def __init__(self, key, data, keyword_map, face_map, aperture_data): self.id = key self.data = data self._caption = su.nn_string(data.get("Caption")).strip() self.comment = su.nn_string(data.get("Comment")).strip() version = None if aperture_data: version = aperture_data.versions.get(key) if data.has_key("DateAsTimerInterval"): self.date = applexml.getappletime(data.get("DateAsTimerInterval")) elif version: self.date = version.image_date else: # Try to get the date from a the caption in "YYYYMMDD ..." format m = re.match(_CAPTION_PATTERN, self._caption) if m: year = int(m.group(1)) month = int(m.group(2)) if not month: month = 1 date = int(m.group(3)) if not date: date = 1 self.date = datetime.datetime(year, month, date) else: self.date = None self.mod_date = applexml.getappletime( data.get("ModDateAsTimerInterval")) self.image_path = data.get("ImagePath") if data.has_key("Rating"): self.rating = int(data.get("Rating")) elif version: self.rating = version.mainRating else: self.rating = None if data.get("longitude"): latitude = float(data.get("latitude")) longitude = float(data.get("longitude")) self.gps = imageutils.GpsLocation(latitude, longitude) elif version: self.gps = version.location else: self.gps = None self.keywords = [] keyword_list = data.get("Keywords") if keyword_list is not None: for i in keyword_list: self.keywords.append(keyword_map.get(i)) elif version: self.keywords = version.keywords if version: self.originalpath = None # This is just a placeholder... # Use the preview if there are adjustments. if (version.rotation or version.hasAdjustments or not su.getfileextension( version.master_image_path) in _JPG_EXTENSIONS): #if version.rotation: # su.pout(u"Rotated: %s (%d)" % (self._caption, version.rotation)) #if version.hasAdjustments: # su.pout(u"Adjustments: %s" % (self._caption)) #if not su.getfileextension(version.master_image_path) in _JPG_EXTENSIONS: # su.pout(u"Not JPEG: %s" % (self._caption)) self.originalpath = version.master_image_path if not version.imageProxy.fullSizePreviewPath: su.pout(u"No preview path for %s." % (self.caption)) else: self.image_path = version.imageProxy.fullSizePreviewPath else: self.image_path = version.master_image_path self.originalpath = None if not version.imageProxy.fullSizePreviewUpToDate: su.pout(u"%s: full size preview not up to date." % (self.caption)) else: self.originalpath = data.get("OriginalPath") self.roll = data.get("Roll") self.albums = [] # list of albums that this image belongs to self.faces = [] self.face_rectangles = [] self.event_name = '' # name of event (roll) that this image belongs to self.event_index = '' # index within event self.event_index0 = '' # index with event, left padded with 0 face_list = data.get("Faces") if face_list: for face_entry in face_list: face_key = face_entry.get("face key") face_name = face_map.get(face_key) if face_name: self.faces.append(face_name) # Rectangle is '{{x, y}, {width, height}}' as ratios, # referencing the lower left corner of the face rectangle, # with lower left corner of image as (0,0) rectangle = parse_face_rectangle( face_entry.get("rectangle")) # Convert to using center of area, relative to upper left corner of image rectangle[0] += rectangle[2] / 2.0 rectangle[1] = max(0.0, 1.0 - rectangle[1] - rectangle[3] / 2.0) self.face_rectangles.append(rectangle) # Other keys in face_entry: face index # Now sort the faces left to right. sorted_names = {} sorted_rectangles = {} for i in xrange(len(self.faces)): x = self.face_rectangles[i][0] while sorted_names.has_key(x): x += 0.00001 sorted_names[x] = self.faces[i] sorted_rectangles[x] = self.face_rectangles[i] self.faces = [ sorted_names[x] for x in sorted(sorted_names.keys()) ] self.face_rectangles = [ sorted_rectangles[x] for x in sorted(sorted_rectangles.keys()) ]