如何使用 eyed3 python 模块为 mp3 设置缩略图? [英] How to set thumbnail for mp3 using eyed3 python module?
问题描述
我无法在 Python 中使用 eyed3 模块为 mp3 文件设置图像缩略图.我尝试下一个脚本:
I can't set image thumbnails for mp3 files using eyed3 module in Python. I try next script:
import eyed3
from eyed3.id3.frames import ImageFrame
th = 'url_to_my_pic'
file = 'to_mp3_pleer/file.mp3'
audiofile = eyed3.load(file)
audiofile.initTag()
audiofile.tag.frames = ImageFrame(image_url=th)
audiofile.tag.save()
但这对我文件中的缩略图没有任何作用.在谷歌中,没有关于使用 eyed3 设置缩略图的信息.如何设置?
But this do nothing with thumbnails in my file. In google no information about settings thumbnails using eyed3. How can I set it?
推荐答案
经过几个小时的eyeD3学习,谷歌搜索和文件封面实验,我想,我有一个解决方案.
After several hours learning of eyeD3, googling and experimenting with file cover, I think, I have a solution for you.
您需要遵循以下规则:
- 使用 ID3v2.3 (不是 eyeD3 中默认的 v2.4);
- 为封面图片添加正确的描述(word
cover
); - 将图像作为二进制传递;
我会给你一个代码示例,它在我的 Windows 10 上运行良好(也应该在其他平台上运行):
I'll give you an example of code, which works fine on my Windows 10 (should works on other platforms as well):
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()
Credits: My code is based on several pages: 1, 2, 3
这篇关于如何使用 eyed3 python 模块为 mp3 设置缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!