Skip to content

Instantly share code, notes, and snippets.

@Vostbur
Created March 11, 2014 13:23
Show Gist options
  • Save Vostbur/9485499 to your computer and use it in GitHub Desktop.
Save Vostbur/9485499 to your computer and use it in GitHub Desktop.
Add cover to ID3v2 tags
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