Python 3.x: Extract front cover from FLAC file and save

1.5k views Asked by At

I was trying to learn the basics of Python during the last months and I found many answers on stackoverflow. But now it's time to ask my first question because I can not find anything helpful.

I have a FLAC audio file and want to extract the front cover and save it to the hard disk using python 3.x. I read the documentation of mutagen, audiotools, eyeD3 ... but I still can not figure out where and how the information is stored.

Could anyone provide a code snippet, please?

Thank you very much.

from mutagen.flac import FLAC, Picture

song = "Anathema - Empty.flac"

var = FLAC(song)
pics = var.pictures
print (pics)
for p in pics:
    if p.type == 3:
        print("\nfound front cover") 
        # how can I save the picture???
1

There are 1 answers

0
Christian On

Here's my solution. Thank you very much for your help!

from mutagen.flac import FLAC, Picture

song = "Anathema - Empty.flac"

var = FLAC(song)
pics = var.pictures
print (pics)
for p in pics:
    if p.type == 3: #front cover
        print("\nfound front cover") 
        with open("cover.jpg", "wb") as f:
            f.write(p.data)