Created
March 11, 2014 13:23
-
-
Save Vostbur/9485499 to your computer and use it in GitHub Desktop.
Add cover to ID3v2 tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mutagen.mp3 import MP3 | |
from mutagen.id3 import ID3, APIC, error | |
audio = MP3('music.mp3', ID3=ID3) | |
# add ID3 tag if it doesn't exist | |
try: | |
audio.add_tags() | |
except error: | |
pass | |
audio.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('image.jpg', 'rb').read() | |
) | |
) | |
audio.save(v2_version=3) # for supporting Windows Media player |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment