diff --git a/pkgs/additional/sane-scripts/src/sane-tag-music b/pkgs/additional/sane-scripts/src/sane-tag-music index d38ee0af6..de98c833d 100755 --- a/pkgs/additional/sane-scripts/src/sane-tag-music +++ b/pkgs/additional/sane-scripts/src/sane-tag-music @@ -10,16 +10,20 @@ # - Artist # - Organization (i.e. record label) # - Performer -# - Producer +# - Producer (N.B.: mutagen supports this for FLAC, but not mp3 or mp4) # - Title # - TrackNumber # - ID3 (mp3): +# - # - Album -# - AlbumArtist (??) +# - AlbumArtist # - Artist # - Band # - Conductor +# - Composer (?) +# - Grouping # - InterpretedBy +# - Publisher (N.B.: mutagen doesn't support this for mp4) # - Subtitle # - Title # - Track @@ -86,6 +90,7 @@ import os.path import mutagen.easyid3 import mutagen.flac import mutagen.mp3 +import mutagen.easymp4 import mutagen.oggopus import mutagen.oggvorbis import pykakasi @@ -522,23 +527,27 @@ class AudioFile(MediaFile): def __init__(self, path_: str): super().__init__(path_) self.muta = None + self.producer_field_name = "producer" - _base, ext = os.path.splitext(path_) + ext = self.ext try: # TODO: handle: - # - .m4a # - .wav # - .wma - if ext == '.flac': + if ext == 'flac': self.muta = mutagen.flac.Open(path_) - elif ext == '.aac': + elif ext == 'aac': # TODO: this seems to only read tags, and not create them? self.muta = mutagen.easyid3.EasyID3(path_) - elif ext == '.mp3': + elif ext == 'mp3': + self.producer_field_name = "grouping" self.muta = mutagen.mp3.EasyMP3(path_) - elif ext == '.ogg': + elif ext in [ 'm4a', 'mp4' ]: + self.producer_field_name = "grouping" + self.muta = mutagen.easymp4.EasyMP4(path_) + elif ext in 'ogg': self.muta = mutagen.oggvorbis.OggVorbis(path_) - elif ext == '.opus': + elif ext == 'opus': self.muta = mutagen.oggopus.OggOpus(path_) else: logger.debug(f"no metadata handler for {path_}") @@ -550,7 +559,7 @@ class AudioFile(MediaFile): album=self.muta.get('album', []) if self.muta else [], albumartist=self.muta.get('albumartist', []) if self.muta else [], artist=self.muta.get('artist', []) if self.muta else [], - producer=self.muta.get('producer', []) if self.muta else [], + producer=self.muta.get(self.producer_field_name, []) if self.muta else [], title=self.muta.get('title', []) if self.muta else [], tracknumber=self.muta.get('tracknumber', []) if self.muta else [], ) @@ -569,7 +578,7 @@ class AudioFile(MediaFile): set_tag('album', tags.album) set_tag('albumartist', tags.albumartist) set_tag('artist', tags.artist) - set_tag('producer', tags.producer) + set_tag(self.producer_field_name, tags.producer) set_tag('title', tags.title) set_tag('tracknumber', tags.tracknumber)