[PYTHON] Display embedded images of mp3 and flac with mutagen

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

Display embedded images of mp3 and flac with mutagen
Wavelet transform of images with PyWavelets and OpenCV
Easy partial download of mp4 with python and youtube-dl!
Create a batch of images and inflate with ImageDataGenerator
Separate color images into RGB images and display them with OpenCV
Graph display of household power consumption with 3GPI and Raspberry Pi
Coexistence of Python2 and 3 with CircleCI (1.0)
Upload and download images with falcon
Get images of OpenStreetMap and Geographical Survey Institute maps with Python + py-staticmaps
Get images of OpenStreetMap and Geographical Survey Institute maps with Python + staticmap
Explanation of creating an application for displaying images and drawing with Python
Calculate and display standard weight with python
Multi-class, multi-label classification of images with pytorch
Import of japandas with pandas 1.0 and above
Capturing images with Pupil, python and OpenCV
Automatically generate images of koalas and bears
Transcription of images with GCP's Vision API
Easily download mp3 / mp4 with python and youtube-dl!
Importing and exporting GeoTiff images with Python
Cut out and connect images with ImageMagick
Let's play with Python Receive and save / display the text of the input form
Shuffle hundreds of thousands of images evenly with tensorflow.
Load caffe model with Chainer and classify images
Convert mp4 to mp3 with ffmpeg (thumbnail embedded version)
Display Google Maps API with Rails and pin display
Coexistence of Fcitx and Zoom ~ With Japanese localization ~
I want to display multiple images with matplotlib.
Categorize face images of anime characters with Chainer
Interactively display algebraic curves with Python and Jupyter
Wrap and display Japanese sentences well with pyglet
Low-rank approximation of images by HOSVD and HOOI
Script to tweet with multiples of 3 and numbers with 3 !!
Noise removal and background transparency of binary images
Implementation of TRIE tree with Python and LOUDS
How to display images continuously with matplotlib Note
Continuation of multi-platform development with Electron and Python
Example of reading and writing CSV with Python
Extract images and tables from pdf with python to reduce the burden of reporting