How do you embed album art into an MP3 using Python? How do you embed album art into an MP3 using Python? python python

How do you embed album art into an MP3 using Python?


Here is how to add example.png as album cover into example.mp3 with mutagen:

from mutagen.mp3 import MP3from mutagen.id3 import ID3, APIC, erroraudio = MP3('example.mp3', ID3=ID3)# add ID3 tag if it doesn't existtry:    audio.add_tags()except error:    passaudio.tags.add(    APIC(        encoding=3, # 3 is for utf-8        mime='image/png', # image/jpeg or image/png        type=3, # 3 is for the cover image        desc=u'Cover',        data=open('example.png').read()    ))audio.save()


I've used the eyeD3 module to do this exact thing.

def update_id3(mp3_file_name, artwork_file_name, artist, item_title):        #edit the ID3 tag to add the title, artist, artwork, date, and genre    tag = eyeD3.Tag()    tag.link(mp3_file_name)    tag.setVersion([2,3,0])    tag.addImage(0x08, artwork_file_name)    tag.setArtist(artist)    tag.setDate(localtime().tm_year)    tag.setTitle(item_title)    tag.setGenre("Trance")    tag.update()


Looks like you have to add a special type of frame to the MP3. See the site on ID3 tags

Also the tutorial for mutagen implies that you can add ID3 tags in mutagen see