I'm running mutagen 1.21 with python 2.7.5 on windows 8, and I get the errors below when I try to use pprint() and save(). If anyone could figure out what the problem is, I would also appreciate a sample code of how to set the title, artist, album artist, album, date and track number of an mp3 file. Also, is it possible to not remove the already existing tags that I don't wish to change? If not, I need a way to get the genre of an mp3 file before it is removed, and then set it again along with the other tags.
code
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.pprint()
audio.save()
traceback
Traceback (most recent call last):
File "id3tag.py", line 5, in <module>
audio.pprint()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 138, in pprint
try: tags = self.tags.pprint()
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 190, in pprint
frames = list(map(Frame.pprint, self.values()))
TypeError: unbound method pprint() must be called with Frame instance as first a
rgument (got str instance instead)
code
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.save()
traceback
Traceback (most recent call last):
File "id3tag.py", line 5, in <module>
audio.save()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 132, in save
return self.tags.save(filename, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 370, in save
framedata = [self.__save_frame(frame) for (key, frame) in frames]
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 461, in __save_frame
framedata = frame._writeData()
AttributeError: 'str' object has no attribute '_writeData'
Edit: (Regarding Michael0x2a's answer) The chart you linked is exactly what I was looking for, but it only worked halfway. Title, track, artist and album all worked fine. For all fields under the mp3 file's properties>details except these four and "year", previous values were cleared by save(), and new ones couldn't be added - lines such as the one you posted,
audio.add(id3.TPE2(encoding=3, text=u"An example"))
did nothing. In particular the "genre" and "album artist" fields don't work. As for "year" which has both the codes TYER and TDAT, it wouldn't change at all unless the field was empty first, and then only by TYER. "ORIGYEAR" with the code TORY does nothing.
The "genre" field isn't actually completely broken - if you change it with python code (audio.add(etc)), or manually go into properties>details beforehand, save() will clear non-built-in genres such as "Technical Death Metal" or "mt3jr39kf390", while it works with built-in genres such as "Classic Rock" or "Country", while certain integers such as 1 or 2 turn into those built-in genres.
Here's the code I used:
from mutagen.id3 import ID3, TIT2, TPE2, TALB, TPE1, TYER, TDAT, TRCK, TCON, TORY, TPUB
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = ID3(p)
audio.add(TIT2(encoding=3, text=u"t")) #TITLE
audio.add(TRCK(encoding=3, text=u"1")) #TRACK
audio.add(TPE1(encoding=3, text=u"a")) #ARTIST
audio.add(TALB(encoding=3, text=u"al")) #ALBUM
audio.add(TYER(encoding=3, text=u"2000")) #YEAR
audio.add(TDAT(encoding=3, text=u"2001")) #YEAR
audio.add(TORY(encoding=3, text=u"2002")) #ORIGYEAR
audio.add(TPE2(encoding=3, text=u"aa")) #ALBUMARTIST
audio.add(TCON(encoding=3, text=u"g")) #GENRE
audio.save()
Edit: I continued the question at Some mutagen tags don't work