Greegko / google-metadata-matcher

Google Photos takeout metadata merger
112 stars 10 forks source link

Workaround for piexif not handling EXIF SceneType tag #7

Open krzkraw opened 11 months ago

krzkraw commented 11 months ago

Workaround for open piexif issue https://github.com/hMatoba/Piexif/issues/95

Greegko commented 11 months ago

Thanks, do you have any example image which is wrong and you get this error ?

konclave commented 10 months ago

I'm having the same issue. Here's the link to the example image: https://storage.yandexcloud.net/konclave-shared-bucket/IMG_20160116_121523675.jpg Adding the changes from the PR fixes the issue.

aiquiti commented 7 months ago

Changes worked for me as well, was failing before around 20 images in

Metadata merging has been finished Success 876 Failed 57

sab1l commented 5 months ago

Changes worked for me as well, was failing before around 20 images in

Metadata merging has been finished Success 876 Failed 57

This should be merged, same here, it would fail before and completes after:

Before:

Total images found: 2772
 |----------------------------------------------------------------------------------------------------| 0.2%
 Current file: blabla.jpg
Traceback (most recent call last):
  File "/Users/.../Library/Python/3.9/lib/python/site-packages/piexif/_dump.py", line 272, in _value_to_bytes
    value_str = raw_value + b"\x00" * (4 - length)
TypeError: can only concatenate tuple (not "bytes") to tuple

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/.../Library/Python/3.9/lib/python/site-packages/piexif/_dump.py", line 335, in _dict_to_bytes
    length_str, value_str, four_bytes_over = _value_to_bytes(raw_value,
  File "/Users/.../Library/Python/3.9/lib/python/site-packages/piexif/_dump.py", line 274, in _value_to_bytes
    raise ValueError("Got invalid type to convert.")
ValueError: Got invalid type to convert.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/.../git/google-metadata-matcher/src/merge_metadata.py", line 26, in <module>
    processFolder(args.source_folder, args.edited_word, args.optimize, args.output_folder, args.max_dimension)
  File "/Users/.../git/google-metadata-matcher/src/process_folder.py", line 96, in processFolder
    new_exif = adjust_exif(image.info["exif"], metadata)
  File "/Users/.../git/google-metadata-matcher/src/auxFunctions.py", line 137, in adjust_exif
    return piexif.dump(exif_dict)
  File "/Users/.../Library/Python/3.9/lib/python/site-packages/piexif/_dump.py", line 68, in dump
    exif_set = _dict_to_bytes(exif_ifd, "Exif", zeroth_length)
  File "/Users/.../Library/Python/3.9/lib/python/site-packages/piexif/_dump.py", line 339, in _dict_to_bytes
    raise ValueError(
ValueError: "dump" got wrong type of exif value.

After:

Total images found: 2772
 Photo format is not supported: blabla.mp4
 Missing image for: blabla(1).json
[...]

Metadata merging has been finished
Success 2381
Failed 391
KoiosLabs commented 3 months ago

Another vote, I also had to update pillow and pillow-heif as there was some images also causing loading issues, not sure if anyone wants to maybe start a fork to merge this stuff into, I can create a pr with my mods if it helps, or even take on the fork if it helps folks. Not a python dev though, its been like 10+ years since I've touched it