Mutagen : How To Extract Album Art Properties?
I am trying to get properties (just width & heigth so far, but probably more later) of an album art picture from an mp3 file using python 3.7.1 and mutagen 1.42, but nothing se
Solution 1:
OK, i eventually figured it out : the EasyID3 module only handles most common tags, and it does not includes picture data (APIC). For that, you need to use the ID3 module, which is way more complex to understand. Then, look for the APIC: key, which stores the picture as a byte string.
Here is a little exemple, using PIL to deal with pictures :
import os,sys
from io import BytesIO
from mutagen.mp3 import MP3
from mutagen.id3 import ID3
from PIL import Image
song_path = os.path.join(sys.argv[1])
track = MP3(song_path)
tags = ID3(song_path)
print("ID3 tags included in this song ------------------")
print(tags.pprint())
print("-------------------------------------------------")
pict = tags.get("APIC:").data
im = Image.open(BytesIO(pict))
print('Picture size : ' + str(im.size))
Hope it helps, good luck ! ;)
Post a Comment for "Mutagen : How To Extract Album Art Properties?"