Cover in FLAC

95 views
Skip to first unread message

rad

unread,
Mar 28, 2010, 7:45:06 AM3/28/10
to Quod Libet Development
Hi guys,
I can not figure out, how to store album cover picture in FLAC file. I
found mutagen.flac.FLAC.add_picture method, but I am not sure, how to
use it.

According to picard (MusicBrainz) source code, it seams, it has to be
instance of mutagen.flac.Picture class, but still I am not able make
it.

Can you please show me some simple example.

Thanks
Radek

rad

unread,
Mar 29, 2010, 6:24:17 AM3/29/10
to Quod Libet Development
>>> from mutagen.flac import FLAC
>>> from mutagen.flac import Picture
>>>
>>> snd = FLAC("pok.flac")
>>>
>>> imgIco = Picture()
>>> imgIco.type = 1
>>> imgIco.mime = 'image/png'
>>> imgIco.desc = 'icon image'
>>> imgIco.width = 32
>>> imgIco.height = 32
>>> imgIco.colors = 0
>>> imgIco.data = open('pok_ico.png', 'r').read()
>>> snd.add_picture(imgIco)
>>>
>>> imgFront = Picture()
>>> imgFront.type = 3
>>> imgFront.mime = 'image/jpeg'
>>> imgFront.desc = 'front cover'
>>> imgFront.width = 100
>>> imgFront.height = 100
>>> imgFront.colors = 0
>>> imgFront.data = open('pok_front.jpg', 'r').read()
>>> snd.add_picture(imgFront)
>>>
>>> imgBack = Picture()
>>> imgBack.type = 4
>>> imgBack.mime = 'image/jpeg'
>>> imgBack.desc = 'back cover'
>>> imgBack.width = 50
>>> imgBack.height = 50
>>> imgBack.colors = 0
>>> imgBack.data = open('pok_back.jpg', 'r').read()
>>> snd.add_picture(imgBack)
>>>
>>> snd.pictures
[<Picture 'image/png' (854 bytes)>, <Picture 'image/jpeg' (2446
bytes)>, <Picture 'image/jpeg' (1157 bytes)>]
>>> snd.save()


For Picture.type see APIC (or http://flac.sourceforge.net/documentation_tools_flac.html#encoding_options).
I am just not sure what Picture.colors means, but it is optional, I
gues.

Best
Radek

Reply all
Reply to author
Forward
0 new messages