0

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

4

1 回答 1

0

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

您需要遵守以下规则:

  • 使用 ID3v2.3 (不是 eyeD3 中默认的 v2.4)
  • 为封面图片(wordcover)添加正确的描述;
  • 将图像作为二进制传递;

我会给你一个代码示例,它在我的 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

于 2021-03-13T19:45:59.950 回答