In order to modify an id3 tag value with mutagen - let's say the track number (TRCK) - I found this:
filename = '/myDir/myFile.mp3'
from mutagen.mp3 import MP3
audio = MP3(fileName)
from mutagen.id3 import ID3NoHeaderError, ID3, TRCK
try:
audio = ID3(fileName)
except ID3NoHeaderError:
print("Adding ID3 header")
audio = ID3()
audio['TRCK'] = TRCK(encoding=3, text=5)
But I don't understand how could I make a function to modify passed tag, something like:
def writeTag(filename, tagName, newValue):
from mutagen.mp3 import MP3
audio = MP3(fileName)
... ???
writeTag('/myDir/myFile.mp3', 'TRCK', 5)
If you want to edit ID3 tags directly, use the ID3 module.
**For information : The tag IDs are summarized in the official documentation at the following link.
It may be easier to use the pprint() method to display the ID3 tags like :
[EDIT] As below an example for all tag id with specific function :