Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read album artwork using python? [closed]

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.

like image 562
Sheldon Avatar asked May 30 '11 01:05

Sheldon


2 Answers

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
like image 177
zeekay Avatar answered Sep 23 '22 05:09

zeekay


ID3 is a rather simple format. If you only need to extract a very limited subset and you want to limit dependencies, then you should consider taking a look at the reference and extracting just the data you're looking for.

like image 25
rid Avatar answered Sep 20 '22 05:09

rid