如何使用eyed3-python模块为mp3设置缩略图



我无法在Python中使用eyed3模块为mp3文件设置图像缩略图。我尝试下一个脚本:

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设置缩略图的信息。我该如何设置?

经过几个小时的eyeD3学习、谷歌搜索和文件封面实验,我想,我有了一个解决方案。

你需要遵守以下规则:

  • 使用ID3v2.3(不是eyeD3中默认的v2.4(
  • 添加封面图像的正确描述(单词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

最新更新