如何使用Python将专辑封面嵌入MP3? [英] How do you embed album art into an MP3 using Python?

查看:324
本文介绍了如何使用Python将专辑封面嵌入MP3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用mutagen读写MP3标签,但是我希望能够将专辑封面直接嵌入文件中.

I've been using mutagen for reading and writing MP3 tags, but I want to be able to embed album art directly into the file.

推荐答案

以下是如何通过诱变将example.png作为专辑封面添加到example.mp3中:

Here is how to add example.png as album cover into example.mp3 with mutagen:

from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error

audio = MP3('example.mp3', ID3=ID3)

# add ID3 tag if it doesn't exist
try:
    audio.add_tags()
except error:
    pass

audio.tags.add(
    APIC(
        encoding=3, # 3 is for utf-8
        mime='image/png', # image/jpeg or image/png
        type=3, # 3 is for the cover image
        desc=u'Cover',
        data=open('example.png').read()
    )
)
audio.save()

这篇关于如何使用Python将专辑封面嵌入MP3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆