4

So I'm using Python 3 and Mutagen, and I know how to remove ALL tag metadata from audio files.

For mp3 files, I simply have to use:

from mutagen.easyid3 import EasyID3
audio = EasyID3(filepath)
audio.delete()
audio.save()

For .flac I have to use:

from mutagen.flac import FLAC
audio = FLAC(filepath)
audio.delete()
audio.clear_pictures()
audio.save()

But what if I want to remove just a single tag? For example, what if I only want to clear ONLY the "date" tag? I'm not sure how to do this for either MP3 files or FLAC audio files, and I'd like to know how to do it for both. How would you clear only a single tag with Mutagen in Python? Thanks.

joejoejoejoe4
  • 1,206
  • 1
  • 18
  • 38

3 Answers3

4

You can set the tag as a blank string and save the file but it'll continue to show up when printing the contents as a blank/empty entry

I found that popping the unwanted tag like an entry in a list seems to work. I only tested with FLAC but I'm sure MP3 would be similar

from mutagen.flac import FLAC
audio = FLAC(filepath)
audio.pop('date')
audio.save()
imblue
  • 41
  • 1
  • 3
2

If you want to remove, let's say, the artwork, you can set the specific tag to an empty list:

from mutagen.id3 import ID3
file = ID3(filepath)
file.setall('APIC', [])
file.save()

That completely removes the tag and the associated artwork.

If you don't know the specific names of the tags you're interested in, you can do:

print(file.pprint())

For reference: https://mutagen.readthedocs.io/en/latest/api/id3.html

michalis
  • 21
  • 1
1

Just assign empty string to it. For example, we want to delete the tracknumber tag:

mp3file = EasyID3(filename)
mp3file["tracknumber"] = ""
mp3file.save()
retif
  • 1,495
  • 1
  • 22
  • 40
  • 1
    As @imblue mentioned, this does not delete the tag. If you print the tags afterwards tracknumber will still show up with a value of an empty string – TheDarkTron Jul 07 '21 at 17:39
  • Indeed, setting empty string value is a silly workaround, popping the tag for good is a much better way. Don't remember why I didn't try that – retif Jul 08 '21 at 08:40