我正在编写一个python脚本,该脚本从服务器下载一个音乐文件,然后从一个URL向它添加一个相册映像,为此,我使用了下面我的原始代码的eyeD3 python库。
import eyed3
mySong = eyed3.load('C:\Users\PC\Music\Test.mp3')
mySong.tag.album_artist = u'Artist-Name'
mySong.tag.images.remove(u'')
mySong.tag.images.set(3, 'None', 'https://upload.wikimedia.org/wikipedia/en/6/60/Recovery_Album_Cover.jpg')
mySong.tag.save()我尝试过这个命令的不同版本,它要么不返回错误,但不像上面的代码那样嵌入图像,要么返回一条错误消息,说明"ValueError: img_url不能是none (当没有图像数据时)“。
在我的另一个选择是直接从一个文件夹中的eyeD3存储下载图像并将其嵌入到其中之前,任何人都能成功地完成这部分,然后删除,显然,我的另一个解决方案会更好。
发布于 2017-10-22 14:16:39
使用
mySong.tag.images.set(type_=3, img_data=None, mime_type=None, description=u"you can put a description here", img_url=u"https://upload.wikimedia.org/wikipedia/en/6/60/Recovery_Album_Cover.jpg")解释:
mySong.tag.images.set正在调用在src/eyed3/id3/tag.py中定义的类ImagesAccessor的set函数。
签字情况如下:
def set(self, type_, img_data, mime_type, description=u"", img_url=None):
"""Add an image of ``type_`` (a type constant from ImageFrame).
The ``img_data`` is either bytes or ``None``. In the latter case
``img_url`` MUST be the URL to the image. In this case ``mime_type``
is ignored and "-->" is used to signal this as a link and not data
(per the ID3 spec)."""发布于 2017-04-25 04:31:56
您可以使用urllib2从URL获取图像的图像数据,然后在eyed3中使用。
import urllib2
response = urllib2.urlopen(your image url)
imagedata = response.read()
import eyed3
file = eyed3.load("song.mp3")
file.tag.images.set(3, imagedata , "image/jpeg" ,u"Description")
file.tag.save()https://stackoverflow.com/questions/40515738
复制相似问题