Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ScribbleGhost/dd700a1da7121f044022440e4bc7eeac to your computer and use it in GitHub Desktop.
Save ScribbleGhost/dd700a1da7121f044022440e4bc7eeac to your computer and use it in GitHub Desktop.
Adding (attaching) pictures or images to MP3 files with the mutagen library in Python 3
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC
audio_path = 'sample_original - Copy.mp3'
audio = MP3(audio_path, ID3=ID3)
# Remember to change to image/jpeg if JPG or image/png if PNG.
# https://mutagen-specs.readthedocs.io/en/latest/id3/id3v2.4.0-frames.html#attached-picture
# Remember that no description should be similar.
audio.tags.add(APIC(encoding=0, mime='image/png', type=0, desc='Other', data=open('images\\Other.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=1, desc='32x32 icon', data=open('images\\32x32 px PNG file icon.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=2, desc='Icon', data=open('images\\Other file icon.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=3, desc='Cover (front)', data=open('images\\Cover (front).png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=4, desc='Cover (back)', data=open('images\\Cover (back).png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=5, desc='Leaflet page', data=open('images\\Leaflet page.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=6, desc='Media', data=open('images\\Media.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=7, desc='Lead artist or lead performer or soloist', data=open('images\\Lead artist or performer.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=8, desc='Artist or performer', data=open('images\\Artist or performer.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=9, desc='Conductor', data=open('images\\Conductor.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=10, desc='Band or Orchestra', data=open('images\\Band or Orchestra.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=11, desc='Composer', data=open('images\\Composer.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=12, desc='Lyricist or text writer', data=open('images\\Lyricist or writer.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=13, desc='Recording Location', data=open('images\\Recording Location.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=14, desc='During recording', data=open('images\\During recording.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=15, desc='During performance', data=open('images\\During performance.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=16, desc='Movie or video screen capture', data=open('images\\Movie or video screen capture.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=17, desc='A bright coloured fish', data=open('images\\A bright coloured fish.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=18, desc='Illustration', data=open('images\\Illustration.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=19, desc='Band or artist logotype', data=open('images\\Band or artist logotype.png','rb').read()))
audio.tags.add(APIC(encoding=0, mime='image/png', type=20, desc='Publisher or Studio logotype', data=open('images\\Publisher or Studio logotype.png','rb').read()))
audio.save() # save the current changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment