mutagen: how to detect and embed album art in mp3, flac and mp4

后端 未结 1 1874
野的像风
野的像风 2021-02-13 22:24

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

相关标签:
1条回答
  • 2021-02-13 22:48

    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
    
    0 讨论(0)
提交回复
热议问题