I'm trying to use a Python 3 script to edit the metadata of MP3 (and other) files using music-tag (0.4.3) but with mixed success. I say "mixed" because it works for some fields and not for others.
I'm wondering if it's related to how I'm using the names of the fields (capitalisation etc.) or the format of the values I'm passing to them, but I couldn't find any good and clear documentation either for music-tag or the standard itself to shed light on this.
To demonstrate the problem with an example, I start by using Mediainfo to look at the metadata of a file before any edits:
'''
General
Complete name : Rossini - William Tell Overture (Fritz Reiner).mp3
Format : MPEG Audio
File size : 1.19 MiB
Duration : 1 min 2 s
Overall bit rate mode : Constant
Overall bit rate : 160 kb/s
Album : Rossini - Ouvertüren
Part/Position : 1
Part/Total : 1
Track name : REINER Wm Tell Over
Track name/Position : 6
Track name/Total : 6
Performer : Fritz Reiner: Chicago Symphony Orchestra
Composer : Gioacchino Rossini/Gioachino Antonio Rossini
Encoded by : iTunes 9.0.1
Genre : Classical
Recorded date : 1958
iTunPGAP : 0
Audio
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 3
Format settings : Joint stereo / MS Stereo
Duration : 1 min 2 s
Bit rate mode : Constant
Bit rate : 160 kb/s
Channel(s) : 2 channels
Sampling rate : 44.1 kHz
Frame rate : 38.281 FPS (1152 SPF)
Compression mode : Lossy
Stream size : 1.18 MiB (100%)'''
Then, I try to update several fields by creating a dict and using that to update the file with music-tag
import music_tag as mtag
from music_tag.id3 import mutagen
from mutagen.id3 import TLAN
metadata_updates = {
"artist": "Rossini",
"album": "Rossini - Overtures",
"year": "1829",
"genre": "Classical music",
"Publisher": "RCA Victor Red Seal",
"Copyright": "Creative Commons Attribution-ShareAlike 4.0 License (Public Domain - Non-PD US)",
"comment": "Test comment",
"language": "French",
"tracknumber": 1,
"totaltracks": 6,
"tracktitle": "Rossini - William Tell Overture (Fritz Reiner)",
"short_title": "William Tell Overture",
"date": "22 November 1958"
}
f = mtag.load_file("Rossini - William Tell Overture (Fritz Reiner).mp3")
for key in metadata_updates:
try:
f[key] = metadata_updates[key]
except:
pass
f.save()
# Output
Error when trying to update Publisher:
'publisher'
Error when trying to update Copyright:
'copyright'
Error when trying to update language:
'language'
Error when trying to update date:
'date'
After this, some fields are updated as intended, but others are not (see errors). In the case of Publisher, Copyright and Language, if
- I open the file with VLC
- open the metadata window
- manually update those fields in the VLC window
- click on Save Metadata
they are saved and appear both in VLC when the file is reopened and in Mediainfo.
Additionally, there seem to be aliases in operation; for example, artist (which is the term used in VLC) seems to go Performer.
The screenshot below shows a comparison of the Mediainfo output in the three states (original version, after Python update, after additional manual update with VLC).
At the end of the day, I'm trying to figure out how to do this properly. A good starting point would be a list/reference showing all valid fields and aliases and any relevant restrictions/specifications on the input values.
Any other useful suggestions would also be appreciated!
