This commit is contained in:
Ignacio Serantes
2026-04-19 12:18:27 +02:00
parent 9d286112b6
commit b5b70326b1
7 changed files with 153 additions and 34 deletions

View File

@@ -121,6 +121,43 @@ class MetadataManager:
return all_metadata
@staticmethod
def write_metadata(path, metadata_dict):
"""
Writes EXIF, IPTC, and XMP metadata back to a file.
Args:
path (str): The path to the image file.
metadata_dict (dict): A dictionary of metadata keys and values.
"""
if not HAVE_EXIV2:
return
try:
image = exiv2.ImageFactory.open(path)
image.readMetadata()
exif = image.exifData()
iptc = image.iptcData()
xmp = image.xmpData()
for key, value in metadata_dict.items():
try:
if key.startswith("Exif."):
exif[key] = str(value)
elif key.startswith("Iptc."):
iptc[key] = str(value)
elif key.startswith("Xmp."):
xmp[key] = str(value)
except Exception as e:
print(f"Error setting metadata key {key}: {e}")
image.writeMetadata()
notify_baloo(path)
mark_app_modified(path)
except Exception as e:
print(f"Error writing metadata for {path}: {e}")
class XattrManager:
"""A manager class to handle reading and writing extended attributes (xattrs)."""