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):
"""
Marquer les fichiers MP3
"""
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) #Artiste
m["TIT2"] = TIT2(encoding=3, text=title) #Titre
m["TALB"] = TALB(encoding=3, text=album) #Nom de l'album
m['TCON'] = TCON(encoding=3, text=genre) #Genre
m['TDRC'] = TDRC(encoding=3, text=date) #Année de sortie
m["TRCK"] = TRCK(encoding=3, text=[str(track + 1)]) #Numéro de piste
#Image de la veste
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