Skip to content

Commit

Permalink
Improved setting 'notes' in Flickr and Ipernity
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-easterbrook committed Dec 23, 2024
1 parent e732c02 commit 6e02973
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
20 changes: 9 additions & 11 deletions src/photini/flickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,19 @@ def set_notes(self, params, photo_id):
return 'Failed to delete note'
# add new notes
for note in params['notes']:
if not note['is_person']:
rsp = self.api_call(
'flickr.photos.notes.add', post=True, photo_id=photo_id,
note_x=note['x'], note_y=note['y'], note_w=note['w'],
note_h=note['h'], note_text=note['content'])
elif note['content'] == self.user_data['fullname']:
if (note['is_person'] and
note['content'] == self.user_data['fullname']):
rsp = self.api_call(
'flickr.photos.people.add', post=True, photo_id=photo_id,
person_x=note['x'], person_y=note['y'], person_w=note['w'],
person_h=note['h'], user_id=self.user_data['user_nsid'])
if rsp is None:
return 'Failed to add person'
# flickr.photos.people.add doesn't show a box, so do it separately
rsp = self.api_call(
'flickr.photos.notes.add', post=True, photo_id=photo_id,
note_x=note['x'], note_y=note['y'], note_w=note['w'],
note_h=note['h'], note_text=note['content'])
if rsp is None:
return 'Failed to add note'
return ''
Expand Down Expand Up @@ -650,11 +653,6 @@ def get_params(self, image, upload_prefs, replace_prefs, photo_id):
params['notes'] = []
for note in image.metadata.image_region.to_notes(image, 500):
params['notes'].append(note)
if note['is_person']:
# Flickr doesn't show box around person, so add one
note = dict(note)
note['is_person'] = False
params['notes'].append(note)
return params

def replace_dialog(self, image):
Expand Down
18 changes: 8 additions & 10 deletions src/photini/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2335,20 +2335,18 @@ def to_notes(self, image, target_size):
for region, note in self.to_note_boundary(image, target_size):
note['content'] = ''
note['is_person'] = False
if region.has_type('human'):
if 'Iptc4xmpExt:PersonInImage' in region:
note['content'] = ', '.join(
region['Iptc4xmpExt:PersonInImage'])
if region.has_type('human') or region.has_type('Face'):
note['content'] = ', '.join(region['Iptc4xmpExt:PersonInImage'])
note['is_person'] = True
elif not any(region.has_role(x) for x in (
'subjectArea', 'mainSubjectArea', 'areaOfInterest')):
continue
if 'dc:description' in region and not note['content']:
note['content'] = MD_LangAlt(
region['dc:description']).best_match()
if 'Iptc4xmpExt:Name' in region and not note['content']:
note['content'] = MD_LangAlt(
region['Iptc4xmpExt:Name']).best_match()
if not note['content']:
note['content'] = region['dc:description'].best_match()
if not note['content']:
note['content'] = ', '.join(region['Iptc4xmpExt:PersonInImage'])
if not note['content']:
note['content'] = region['Iptc4xmpExt:Name'].best_match()
if not note['content']:
continue
result.append(note)
Expand Down

0 comments on commit 6e02973

Please sign in to comment.