v0.9.24
This commit is contained in:
@@ -9,6 +9,7 @@ Classes:
|
||||
"""
|
||||
import os
|
||||
import collections
|
||||
import logging
|
||||
from PySide6.QtDBus import QDBusConnection, QDBusMessage, QDBus
|
||||
try:
|
||||
import exiv2
|
||||
@@ -21,6 +22,8 @@ except ImportError:
|
||||
from utils import preserve_mtime
|
||||
from constants import RATING_XATTR_NAME, XATTR_NAME
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_app_modified_callback = None
|
||||
|
||||
MetadataResult = collections.namedtuple('MetadataResult', ['tags', 'rating'])
|
||||
@@ -141,6 +144,31 @@ class MetadataManager:
|
||||
iptc = image.iptcData()
|
||||
xmp = image.xmpData()
|
||||
|
||||
# Remove keys that are no longer in the dictionary
|
||||
containers = [
|
||||
(exif, exiv2.ExifKey, "Exif."),
|
||||
(iptc, exiv2.IptcKey, "Iptc."),
|
||||
(xmp, exiv2.XmpKey, "Xmp.")
|
||||
]
|
||||
|
||||
for container, key_class, prefix in containers:
|
||||
keys_to_remove = []
|
||||
for datum in container:
|
||||
k = datum.key()
|
||||
# Only consider keys belonging to this specific container
|
||||
if k.startswith(prefix) and k not in metadata_dict:
|
||||
keys_to_remove.append(k)
|
||||
|
||||
for key in keys_to_remove:
|
||||
try:
|
||||
x_key = key_class(key)
|
||||
it = container.findKey(x_key)
|
||||
if it != container.end():
|
||||
container.erase(it)
|
||||
except Exception as e:
|
||||
print(f"Error removing metadata key {key}: {e}")
|
||||
|
||||
# Set or update values from the dictionary
|
||||
for key, value in metadata_dict.items():
|
||||
try:
|
||||
if key.startswith("Exif."):
|
||||
@@ -156,7 +184,13 @@ class MetadataManager:
|
||||
notify_baloo(path)
|
||||
mark_app_modified(path)
|
||||
except Exception as e:
|
||||
print(f"Error writing metadata for {path}: {e}")
|
||||
error_msg = str(e)
|
||||
if "kerTooLargeJpegSegment" in error_msg or "38" in error_msg:
|
||||
msg = UITexts.ERROR_JPEG_METADATA_LIMIT.format(os.path.basename(path))
|
||||
logger.error(msg)
|
||||
raise IOError(msg) from e
|
||||
logger.error(f"Error writing metadata for {path}: {e}")
|
||||
raise
|
||||
|
||||
|
||||
class XattrManager:
|
||||
|
||||
Reference in New Issue
Block a user