import mutagen
from io import BytesIO
from PIL import Image
#Please change the file name as appropriate
file = r"example.mp3"
#File reading
audio = mutagen.File(file)
#Get a list of images
if 'audio/mp3' in audio.mime:
images = [audio[i] for i in audio if "APIC" in i]
elif 'audio/flac' in audio.mime:
images = audio.pictures
for imgb in images:
#Convert image for display
img = Image.open(BytesIO(imgb.data))
img.show()
Even if I searched, there were only articles that newly embed images, and I could not find an article that displays the embedded image, so I wrote it.
** "APIC" in i ** instead of ** "APIC" == i ** The key of the image embedded with Mp3tag was ** "APIC:" **.
It may not be the best code because I wrote it in the textbook.
Recommended Posts