How do I read album artwork using python?

Sheldon picture Sheldon · May 30, 2011 · Viewed 8.7k times · Source

In my searches I have found that there are a few libraries that might be able to do this by reading ID3 tags. If so - which one would be the best to use? I don't plan on writing any data just reading.

Also I'm trying to make this app as portable as possible so the least amount of dependencies would be a huge bonus.

Would appreciate some advice. Thanks.

Answer

zeekay picture zeekay · May 30, 2011

I'd recommend mutagen, it's a pure python library with no other dependencies and it supports a lot of different audio metadata formats/tags (MP3, FLAC, M4A, Monkey's Audio, Musepack, and more). To extract artwork from an ID3 v2.4 MP3 saved with iTunes:

from mutagen import File

file = File('some.mp3') # mutagen can automatically detect format and type of tags
artwork = file.tags['APIC:'].data # access APIC frame and grab the image
with open('image.jpg', 'wb') as img:
   img.write(artwork) # write artwork to new image