3

i am working on a python script that downloads a music file from a server and then adds an album image to it from a URL, for this i am using the eyeD3 python library my original code below.

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()

I have tried different versions of this command and it either returns no errors but does not embed the image as the above code does or returns an error message stating "ValueError: img_url MUST not be none when no image data".

Anyone had any success with this part of eyeD3 before my other alternative is download image direct from URL store in a folder and embed from there then delete obviously my other solution would be better.

4

2 回答 2

6

您可以使用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()
于 2017-04-25T04:31:56.237 回答
4

利用

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正在调用中定义set的类的函数。ImagesAccessorsrc/eyed3/id3/tag.py

签名如下:

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-10-22T14:16:39.463 回答