经过几个小时的 eyeD3 学习、谷歌搜索和文件封面实验,我想,我有一个解决方案给你。
您需要遵守以下规则:
- 使用 ID3v2.3 (不是 eyeD3 中默认的 v2.4);
- 为封面图片(word
cover
)添加正确的描述;
- 将图像作为二进制传递;
我会给你一个代码示例,它在我的 Windows 10 上运行良好(也应该在其他平台上运行):
import eyed3
import urllib.request
audiofile = eyed3.load("D:\\tmp\\tmp_mp3\\track_example.mp3")
audiofile.initTag(version=(2, 3, 0)) # version is important
# Other data for demonstration purpose only (from docs)
audiofile.tag.artist = "Token Entry"
audiofile.tag.album = "Free For All Comp LP"
audiofile.tag.album_artist = "Various Artists"
audiofile.tag.title = "The Edge"
# Read image from local file (for demonstration and future readers)
with open("D:\\tmp\\tmp_covers\\cover_2021-03-13.jpg", "rb") as image_file:
imagedata = image_file.read()
audiofile.tag.images.set(3, imagedata, "image/jpeg", u"cover")
audiofile.tag.save()
# Get image from the Internet
response = urllib.request.urlopen("https://example.com/your-picture-here.jpg")
imagedata = response.read()
audiofile.tag.images.set(3, imagedata, "image/jpeg", u"cover")
audiofile.tag.save()
学分:我的代码基于几个页面:1、2、3