I\'d like to be able to detect whether an audio file has embedded album art and, if not, add album art to that file. I\'m using mutagen
1) Detecting album art. Is there
Embed flac:
from mutagen import File
from mutagen.flac import Picture, FLAC
def add_flac_cover(filename, albumart):
audio = File(filename)
image = Picture()
image.type = 3
if albumart.endswith('png'):
mime = 'image/png'
else:
mime = 'image/jpeg'
image.desc = 'front cover'
with open(albumart, 'rb') as f: # better than open(albumart, 'rb').read() ?
image.data = f.read()
audio.add_picture(image)
audio.save()
For completeness, detect picture
def pict_test(audio):
try:
x = audio.pictures
if x:
return True
except Exception:
pass
if 'covr' in audio or 'APIC:' in audio:
return True
return False