From 721f45f7d489d2358c5c827f92da30b733e38a00 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 11 Jul 2024 23:33:02 +0000 Subject: [PATCH] sane-tag-music: dont abort if metadata fails to load --- .../sane-scripts/src/sane-tag-music | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/pkgs/additional/sane-scripts/src/sane-tag-music b/pkgs/additional/sane-scripts/src/sane-tag-music index a21179267..3b23aefa9 100755 --- a/pkgs/additional/sane-scripts/src/sane-tag-music +++ b/pkgs/additional/sane-scripts/src/sane-tag-music @@ -45,9 +45,19 @@ # - XPAuthor (intended as fallback when Artist is unset) # - XPSubject (i.e. who is in the photo) # - XMP (GIF, PDF, JPEG, PNG): -# - XMP:Album -# - XMP:Author -# - XMP:Producer +# - Album +# - Author +# - Composer +# - Director +# - DirectorPhotography +# - DiscNumber +# - Engineer +# - Group (?) +# - Label +# - Producer (Adobe products use this for their own branding) +# - ShotNumber +# - TapeName +# - TrackNumber # mutagen docs: # - """ @@ -350,6 +360,17 @@ class Tags: if self.albumartist == [ "Various Artists" ] and self.producer == [ "Various Artists" ]: self.producer = [] + producers = [] + for p in self.producer: + if "adobe photoshop" in p.lower(): + continue + if "adobe pdf" in p.lower(): + continue + if "ij scan utility" in p.lower(): + continue + producers.append(p) + self.producer = producers + def rewrite_singles(self) -> None: """ Singles shouldn't generally have a track number: delete it @@ -513,7 +534,13 @@ class MutagenMetadata(MetadataImpl): super().__init__(path_=path_) self.muta = muta - def new(path_: str, muta) -> 'MutagenMetadata | None': + def new(path_: str, opener) -> 'MutagenMetadata | None': + muta = None + try: + muta = opener(path_) + except Exception as e: + logger.debug(f"failed to open metadata for {path_}: {e!r}") + if muta is None: return None return MutagenMetadata(path_, muta) @@ -619,19 +646,19 @@ class MediaFile: if ext == "aac": # TODO: this seems to only read tags, and not create them? - meta = MutagenMetadata.new(f, mutagen.easyid3.EasyID3(f)) + meta = MutagenMetadata.new(f, mutagen.easyid3.EasyID3) elif ext == "flac": - meta = MutagenMetadata.new(f, mutagen.flac.Open(f)) + meta = MutagenMetadata.new(f, mutagen.flac.Open) elif ext == 'mp3': tag_field_names.producer = "grouping" - meta = MutagenMetadata.new(f, mutagen.mp3.EasyMP3(f)) + meta = MutagenMetadata.new(f, mutagen.mp3.EasyMP3) elif ext in [ 'm4a', 'mp4' ]: tag_field_names.producer = "grouping" - meta = MutagenMetadata.new(f, mutagen.easymp4.EasyMP4(f)) + meta = MutagenMetadata.new(f, mutagen.easymp4.EasyMP4) elif ext in 'ogg': - meta = MutagenMetadata.new(f, mutagen.oggvorbis.OggVorbis(f)) + meta = MutagenMetadata.new(f, mutagen.oggvorbis.OggVorbis) elif ext == 'opus': - meta = MutagenMetadata.new(f, mutagen.oggopus.OggOpus(f)) + meta = MutagenMetadata.new(f, mutagen.oggopus.OggOpus) elif ext == "gif": tag_field_names.album = "XMP:Album" tag_field_names.albumartist = "XMP:Author"