python
$ pip install mutagen
python
from mutagen.id3 import ID3, TIT2, TALB, TPE1, TRCK, APIC, TDRC, TCON
from mutagen.mp3 import MP3
import mutagen.id3
def sample(filename, album, artist, title, track, genre, date, description, savepath):
"""
Tag MP3-Dateien
"""
m = MP3(filename, ID3=ID3)
try:
m.add_tags(ID3=ID3)
#print("Added tags to %s" % filename)
except mutagen.id3.error:
#print("%s already had tags" % filename)
pass
m["TPE1"] = TPE1(encoding=3, text=artist) #Künstler
m["TIT2"] = TIT2(encoding=3, text=title) #Titel
m["TALB"] = TALB(encoding=3, text=album) #Albumname
m['TCON'] = TCON(encoding=3, text=genre) #Genre
m['TDRC'] = TDRC(encoding=3, text=date) #Erscheinungsjahr
m["TRCK"] = TRCK(encoding=3, text=[str(track + 1)]) #Titelnummer
#Jackenbild
if savepath:
m.tags.add(
APIC(
encoding=3, # 3 is for utf-8
mime='image/jpeg', # image/jpeg or image/png
type=3, # 3 is for the cover image
desc=u'Cover',
data=open(savepath).read()
)
)
m.save()
Recommended Posts