首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用eyeD3从URL嵌入相册艺术

使用eyeD3从URL嵌入相册艺术
EN

Stack Overflow用户
提问于 2016-11-09 20:46:04
回答 2查看 5.6K关注 0票数 3

我正在编写一个python脚本,该脚本从服务器下载一个音乐文件,然后从一个URL向它添加一个相册映像,为此,我使用了下面我的原始代码的eyeD3 python库。

代码语言:javascript
复制
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存储下载图像并将其嵌入到其中之前,任何人都能成功地完成这部分,然后删除,显然,我的另一个解决方案会更好。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-10-22 14:16:39

使用

代码语言:javascript
复制
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中定义的类ImagesAccessorset函数。

签字情况如下:

代码语言:javascript
复制
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)."""
票数 4
EN

Stack Overflow用户

发布于 2017-04-25 04:31:56

您可以使用urllib2从URL获取图像的图像数据,然后在eyed3中使用。

代码语言:javascript
复制
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()
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40515738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档