def redraw_markers(self): if not self.map_loaded: return for info in self.marker_info.values(): info['images'] = [] for image in self.image_list.get_images(): latlong = image.metadata.latlong if not latlong: continue for info in self.marker_info.values(): if info['latlong'] == latlong: info['images'].append(image) break else: for i in range(len(self.marker_info) + 2): marker_id = i if marker_id not in self.marker_info: break self.marker_info[marker_id] = { 'images': [image], 'latlong': LatLon(latlong), 'selected': image.selected, } self.JavaScript('addMarker({:d},{!r},{!r},{:d})'.format( marker_id, latlong['lat'], latlong['lon'], image.selected)) for marker_id in list(self.marker_info.keys()): info = self.marker_info[marker_id] if not info['images']: self.JavaScript('delMarker({:d})'.format(marker_id)) del self.marker_info[marker_id] elif info['selected'] != any([x.selected for x in info['images']]): info['selected'] = not info['selected'] self.JavaScript('enableMarker({:d},{:d})'.format( marker_id, info['selected']))
def _merge_metadata(self, photo_id, image): photo = self.session.get_info(photo_id) if not photo: return md = image.metadata # sync title title = html.unescape(photo['title']['_content']) if md.title: md.title = md.title.merge( image.name + '(title)', 'flickr title', title) else: md.title = title # sync description description = html.unescape(photo['description']['_content']) if md.description: md.description = md.description.merge( image.name + '(description)', 'flickr description', description) else: md.description = description # sync keywords tags = [] for tag in photo['tags']['tag']: if tag['raw'] == 'uploaded:by=photini': continue if md.location_taken and tag['raw'] in ( md.location_taken['CountryCode'], md.location_taken['CountryName'], md.location_taken['ProvinceState'], md.location_taken['City']): continue tags.append(tag['raw']) md.keywords = md.keywords.merge( image.name + '(keywords)', 'flickr tags', tags) # sync location if 'location' in photo: location = photo['location'] latlong = LatLon((location['latitude'], location['longitude'])) if md.latlong: md.latlong = md.latlong.merge( image.name + '(latlong)', 'flickr location', latlong) else: md.latlong = latlong address = {} for key in location: if '_content' in location[key]: address[key] = location[key]['_content'] location_taken = Location.from_address(address, self._address_map) if md.location_taken: md.location_taken = md.location_taken.merge( image.name + '(location_taken)', 'flickr location', location_taken) else: md.location_taken = location_taken # sync date_taken if photo['dates']['takenunknown'] == '0': granularity = int(photo['dates']['takengranularity']) if granularity >= 6: precision = 1 elif granularity >= 4: precision = 2 else: precision = 6 date_taken = DateTime(( datetime.strptime( photo['dates']['taken'], '%Y-%m-%d %H:%M:%S'), precision, None)) if md.date_taken: md.date_taken = md.date_taken.merge( image.name + '(date_taken)', 'flickr date taken', date_taken) else: md.date_taken = date_taken
def marker_drag_end(self, lat, lng, marker_id): info = self.marker_info[marker_id] for image in info['images']: image.metadata.latlong = lat, lng info['latlong'] = LatLon((lat, lng)) self.coords.refresh()
def _merge_metadata(self, photo_id, image): try: rsp = self.session.photos.getInfo(photo_id=photo_id) except flickrapi.FlickrError as ex: logger.error(str(ex)) return if rsp['stat'] != 'ok': return photo = rsp['photo'] md = image.metadata h = HTMLParser() # sync title title = h.unescape(photo['title']['_content']) if md.title: md.title = md.title.merge(image.name + '(title)', 'flickr title', title) else: md.title = title # sync description description = h.unescape(photo['description']['_content']) if md.description: md.description = md.description.merge(image.name + '(description)', 'flickr description', description) else: md.description = description # sync keywords tags = [] for tag in photo['tags']['tag']: if tag['raw'] == 'uploaded:by=photini': continue if md.location_taken and tag['raw'] in ( md.location_taken.country_code, md.location_taken.country_name, md.location_taken.province_state, md.location_taken.city): continue tags.append(tag['raw']) md.keywords = md.keywords.merge(image.name + '(keywords)', 'flickr tags', tags) # sync location if 'location' in photo: location = photo['location'] latlong = LatLon((location['latitude'], location['longitude'])) if md.latlong: md.latlong = md.latlong.merge(image.name + '(latlong)', 'flickr location', latlong) else: md.latlong = latlong address = {} for key in location: if '_content' in location[key]: address[key] = location[key]['_content'] location_taken = Location.from_address(address, self._address_map) if md.location_taken: md.location_taken = md.location_taken.merge( image.name + '(location_taken)', 'flickr location', location_taken) else: md.location_taken = location_taken # sync date_taken if photo['dates']['takenunknown'] == '0': granularity = int(photo['dates']['takengranularity']) if granularity >= 6: precision = 1 elif granularity >= 4: precision = 2 else: precision = 6 date_taken = DateTime( (datetime.strptime(photo['dates']['taken'], '%Y-%m-%d %H:%M:%S'), precision, None)) if md.date_taken: md.date_taken = md.date_taken.merge( image.name + '(date_taken)', 'flickr date taken', date_taken) else: md.date_taken = date_taken