linuxfileid3flacvorbis

How to get audio file metadata container's data for flac and ogg


Is there a command to tell me what type of metadata container is using a file?

Something like: command myfile.flac saying: vorbis comment or id3v2.


Solution

  • Warning: One audio file can have multiple metadata containers. So finding vorbis comment doesn't mean there is no id3 tags. Reminder: flac and ogg should be used with vorbis comment.

    Vorbis comment

    Flac

    metaflac --list myfile.flac
    

    It will print a lot of info for each block. Here is the answer:

    METADATA block #2
      type: 4 (VORBIS_COMMENT)
    

    To install metaflac: sudo apt install flac.

    Ogg

    vorbiscomment file.ogg
    

    It will output something like:

    encoder=Lavc57.107.100 libvorbis
    TRACKNUMBER=1
    title=My file title
    ...
    

    To install: sudo apt install vorbis-tools

    ID3

    Well, the best thing I found is a python library: mutagen. For example, in your python file you can write:

    from mutagen.id3 import ID3NoHeaderError, ID3
    
    try:
        tags = ID3("path/to/myfile.ogg")
        print("ID3 tags found: ", tags)
    except ID3NoHeaderError:
        print("No ID3 tags")
    

    Output for file with ID3 tags: ID3 tags found: {'TIT2': TIT2(encoding=<Encoding.UTF8: 3>, text=['my new title'])}. It works also for flac files.