icloud-photos-downloader / icloud_photos_downloader

A command-line tool to download photos from iCloud
MIT License
6.66k stars 539 forks source link

Add keywords to image metadata #102

Open artemryzhov opened 6 years ago

artemryzhov commented 6 years ago

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 commented 6 years ago

Hi, wow that sounds difficult! Sorry but I've never really used the piexif or iptcinfo libraries, so I won't be able to help very much. (Someone else contributed the piexif code.) But it sounds like a great idea for a feature, and I'd be happy to merge a PR if you can get it working.

On Mon, Sep 24, 2018 at 1:48 AM Artem Ryzhov notifications@github.com wrote:

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...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ndbroadbent/icloud_photos_downloader/issues/102, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIhENY16dtrz0ChPk7a1EOgiV2aAqJaks5ud9dlgaJpZM4W101h .

adamshand commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

yes, manually tagging the photos with album name would work

RhetTbull commented 4 years ago

@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 commented 4 years ago

Thank you for your email and for contributing.

On Mon, Apr 27, 2020 at 11:21 PM Rhet Turnbull notifications@github.com wrote:

@adamshand https://github.com/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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ndbroadbent/icloud_photos_downloader/issues/102#issuecomment-620404961, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALE26ZVELZJMIUTBPBZCPMDROZYWNANCNFSM4FWXJVQQ .

adamshand commented 4 years ago

@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! :-)