Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keywords to image metadata #102

Open
artemryzhov opened this issue Sep 23, 2018 · 8 comments
Open

Add keywords to image metadata #102

artemryzhov opened this issue Sep 23, 2018 · 8 comments

Comments

@artemryzhov
Copy link
Contributor

artemryzhov commented Sep 23, 2018

Hi!

I want to implement feature that add keywords to image metadata, by icloud album title. For example, I have 10 photos in album named "Test album", and I want to images have keyword "Test album", for quick search in Shotwell.

The difficulty in implementing data writing to a file..

I tried via piexif:

  exif_dict = piexif.load(path)
  exif_dict.get("0th")[40094] = tags // tags is string 'tag1,tag2'
  exif_bytes = piexif.dump(exif_dict)
  piexif.insert(exif_bytes, path)       

and got error

    zeroth_set = _dict_to_bytes(zeroth_ifd, "0th", 0)
  File "/usr/local/lib/python2.7/dist-packages/piexif/_dump.py", line 337, in _dict_to_bytes
    offset)
  File "/usr/local/lib/python2.7/dist-packages/piexif/_dump.py", line 193, in _value_to_bytes
    value_str = (_pack_byte(*raw_value) +
  File "/usr/local/lib/python2.7/dist-packages/piexif/_dump.py", line 162, in _pack_byte
    return struct.pack("B" * len(args), *args)
struct.error: cannot convert argument to integer

via iptcinfo:

        iptc.keywords = []
        tags = [x.strip() for x in tags.split(',')];
        iptc.keywords.extend(tags)
        iptc.save()

no errors, and no results - tags wasn't written to file...

Help, please...

@ndbroadbent
Copy link
Collaborator

ndbroadbent commented Sep 23, 2018 via email

@adamshand
Copy link

@artemryzhov did you ever find a way of doing this? I'm loving this as a way to get my photos out of iCloud, but losing 15 years worth of albums is a bummer. :-)

@RhetTbull
Copy link

@adamshand are your photos in Photos.app on a Mac or only in iCloud? If they're in Photos, I've written a tool (osxphotos) that will export them while preserving album and folder structure. It also preserves all metadata such as keywords and people in the image. It does not yet preserve album name as a keyword but that's in my backlog of "to do" features. If photos are in iCloud only, this won't help.

@adamshand
Copy link

I found your software shortly after posting this. It looks great, thanks!!

Unfortunately most of my photos are in icloud, but I’ve moved my library to an external HD and told iPhoto to start downloading them all. Pretty slow going so far but hopefully it’ll get there eventually!

I guess I can manually tag all my albums before running osxphotos as a work-a-round?

Thanks!!

@RhetTbull
Copy link

yes, manually tagging the photos with album name would work

@RhetTbull
Copy link

@adamshand I've gone ahead and implemented the feature to optionally add albums (and optionally persons) as keywords when exporting metadata to osxphotos. e.g.
python3 -m osxphotos export ~/path/to/export --directory "{album}" --album-keywords --exiftool --sidecar xmp

will export all photos, write metadata (including album name) to EXIF keywords and an XMP sidecar file and organize into directories based on album name

This fix in v0.28.7 on github.

@metahnetoutage
Copy link

metahnetoutage commented Apr 28, 2020 via email

@adamshand
Copy link

@RhetTbull that's amazing! Photos are almost done downloading (will finish overnight) and I was just starting to experiment with tagging my albums by hand. Which was looking pretty tediously slow ... so thanks heaps! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants