quodlibet / mutagen

Python module for handling audio metadata

Home Page:https://mutagen.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Universal" audio metadata class

kubinka0505 opened this issue · comments

Hi. While using mutagen I clearly see that there are multiple tagging systems, like ID3, VCFLACDict (mutagen._vorbis.VCommentDict), etc. but is there a util that can convert one tagging system to another?

>>> from mutagen import File as mFile
>>> list(mFile("File.flac"))
['artist', 'title']
>>> list(mFile("File.mp3"))
['TIT2', 'TPE1']

This system makes universal tags detection very hard.

>>> Files = "File.flac", "File.mp3"
>>> for File in Files:
...     print(f'"{File}" title is: {mFile(File)["title"]}')
... 
"File.flac" title is: ['Masterpiece']
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Users\kubinka0505\AppData\Local\Programs\Python\Python311\Lib\site-packages\mutagen\_file.py", line 62, in __getitem__
    return self.tags[key]
           ~~~~~~~~~^^^^^
  File "C:\Users\kubinka0505\AppData\Local\Programs\Python\Python311\Lib\site-packages\mutagen\_util.py", line 536, in __getitem__
    return self.__dict[key]
           ~~~~~~~~~~~^^^^^
KeyError: 'title'

Is there a workaround for this? FFmpeg can convert very small amout of tags with -map_metadata 0 -id3v2_version 3 but it's not Pythonic to use external package.
Hence mutagen is a Python module for handling audio metadata, maybe there's a workaround for it?
Something like:

>>> from mutagen import UniversalTag as UT
>>> list(UT("File.flac"))
['Artist', 'Title']
>>> list(UT("File.mp3"))
['Artist', 'Title']
>>>

@kubinka0505 Take a look at https://github.com/beetbox/mediafile , it is a wrapper around mutagen providing such a unified abstraction.

Keep in mind that such unification will always be opinionated. You can strive for making this as compatible as possible, but the use of the individual tag fields provided by various tagging standards is in many cases not clear and used differently by different software. But mediafile uses in general best practices, it is also used by the popular beets audio library management tool.

As a side note I personally really believe that this abstraction is better placed in a separate library like mediafile and that mutagen should focus on supporting the technical details of the tag standards it supports.

There is the earlier issue #489 discussing this feature request.