sane-tag-music: fix ImageFile to actually support tag deletion

This commit is contained in:
2024-07-10 00:48:22 +00:00
parent 3ae650bcae
commit 2697d068ce

View File

@@ -511,6 +511,7 @@ class AudioFile(MediaFile):
class ImageFile(MediaFile): class ImageFile(MediaFile):
_exiftool = None # static, lazy init _exiftool = None # static, lazy init
TAG_PREFIXES = ("", "EXIF:", "PNG:", "XMP:")
def __init__(self, path_: str): def __init__(self, path_: str):
super().__init__(path_) super().__init__(path_)
@@ -536,10 +537,8 @@ class ImageFile(MediaFile):
acc += [t for t in new if t not in acc] acc += [t for t in new if t not in acc]
def get_tag(name: str) -> list: def get_tag(name: str) -> list:
acc = [] acc = []
append_tags(acc, get_tag_(name)) for prefix in self.TAG_PREFIXES:
append_tags(acc, get_tag_(f"EXIF:{name}")) append_tags(acc, get_tag_(f"{prefix}{name}"))
append_tags(acc, get_tag_(f"PNG:{name}"))
append_tags(acc, get_tag_(f"XMP:{name}"))
return acc return acc
return Tags( return Tags(
@@ -560,8 +559,12 @@ class ImageFile(MediaFile):
if len(val) == 1: if len(val) == 1:
self.exif[name] = val[0] self.exif[name] = val[0]
elif len(val) == 0: elif len(val) == 0:
if name in self.exif: # tags are deleted by setting them "",
del self.exif[name] # and we have to clear all possible tag variants else the deleted one will be re-derived from the others next read.
for prefix in self.TAG_PREFIXES:
pname = f"{prefix}{name}"
if pname in self.exif:
self.exif[pname] = ""
else: else:
logger.warning(f"multiple values for tag {name}: {val!r}") logger.warning(f"multiple values for tag {name}: {val!r}")