Nicole Portas 2 місяців тому
батько
коміт
d02326aa9e
1 змінених файлів з 15 додано та 3 видалено
  1. 15 3
      exif_change_date.py

+ 15 - 3
exif_change_date.py

@@ -22,6 +22,17 @@ def get_arbitrary_date():
         except ValueError:
             print("Incorrect format. You must use YYYY-MM-DD HH:MM:SS or press Enter for 1970. Try again.", file=sys.stderr)
 
+def sanitize_exif_dict(exif_dict):
+    """Fixes type mismatches in raw EXIF tags that make piexif.dump choke."""
+    if "Exif" in exif_dict:
+        # Tag 41729 is SceneType. Must be bytes.
+        if 41729 in exif_dict["Exif"] and isinstance(exif_dict["Exif"][41729], int):
+            exif_dict["Exif"][41729] = bytes([exif_dict["Exif"][41729]])
+        # Tag 41728 is FileSource. Must be bytes.
+        if 41728 in exif_dict["Exif"] and isinstance(exif_dict["Exif"][41728], int):
+            exif_dict["Exif"][41728] = bytes([exif_dict["Exif"][41728]])
+    return exif_dict
+
 def update_file_timestamps(file_path, exif_date_str):
     """Updates EXIF metadata/native chunks based on format, and sets filesystem mtime/atime."""
     try:
@@ -39,6 +50,7 @@ def update_file_timestamps(file_path, exif_date_str):
         try:
             try:
                 exif_dict = piexif.load(str(file_path))
+                exif_dict = sanitize_exif_dict(exif_dict)
             except Exception:
                 exif_dict = {"0th": {}, "Exif": {}, "GPS": {}, "Interop": {}, "1st": {}, "thumbnail": None}
 
@@ -104,7 +116,7 @@ def main():
 
     valid_extensions = {
         '.jpg', '.jpeg', '.png', '.webp', '.tiff', '.tif', 
-        '.bmp', '.gif', '.heic', '.heif', '.cr2', '.nef'
+        '.bmp', '.gif', '.heic', '.heif', '.cr2', '.nef', '.webm'
     }
     
     try:
@@ -117,10 +129,10 @@ def main():
         sys.exit(1)
 
     if not image_files:
-        print("No matching images found in this directory or subdirectories.")
+        print("No matching files found in this directory or subdirectories.")
         return
 
-    print(f"Found {len(image_files)} images recursively under {current_dir}")
+    print(f"Found {len(image_files)} files recursively under {current_dir}")
     target_date = get_arbitrary_date()
 
     print(f"\nProcessing files concurrently using target date: {target_date}...")