quodlibet / mutagen

Python module for handling audio metadata
https://mutagen.readthedocs.io
GNU General Public License v2.0
1.48k stars 158 forks source link

Writing Library Tag #644

Open Abhi5033 opened 3 months ago

Abhi5033 commented 3 months ago

This maybe not actually an issue

After muxing a flac file using ffmpeg, I'm trying to add metadata using Mutagen. Post processing in mutagen, the file is still showing Writing Library as ffmpeg in the mediainfo instead of Mutagen.

What I want image

What I'm getting image

I'm trying below code

def add_metadata_to_flac(file_path, metadata):
    audio = FLAC(file_path)
    audio.clear()
    with open("cover.jpg", "rb") as f:
        image = f.read()
    picture = mutagen.flac.Picture()
    picture.type = 3
    picture.data = image
    audio.add_picture(picture)

    for key, value in metadata.items():
        audio[key] = str(value)
    audio.save()

Can someone please help me? I don't want ffmpeg to be displayed as writing library

phw commented 3 months ago

Indeed, currently Mutagen does not update the vendor string on the vorbis comments, it just sets it when there is no Vorbis comment block yet in the file and mutagen creates a new one. See https://github.com/quodlibet/mutagen/blob/main/mutagen/_vorbis.py#L73

You could set it in your code, though. I think the following should work:

audio.tags.vendor = "Mutagen " + mutagen.version_string

Should mutagen update it by default every time it writes? Probably, I'm not sure. I personally would say yes, but some users might want to preserve the current behavior.

I think it definitely should update it when calling VComment.clear.

Abhi5033 commented 3 months ago

Indeed, currently Mutagen does not update the vendor string on the vorbis comments, it just sets it when there is no Vorbis comment block yet in the file and mutagen creates a new one. See https://github.com/quodlibet/mutagen/blob/main/mutagen/_vorbis.py#L73

You could set it in your code, though. I think the following should work:

audio.tags.vendor = "Mutagen " + mutagen.version_string

Should mutagen update it by default every time it writes? Probably, I'm not sure. I personally would say yes, but some users might want to preserve the current behavior.

I think it definitely should update it when calling VComment.clear.

Thank you So Much Sir. It worked.