TypeError:无法将JpegImageFile连接为字节

时间:2019-11-14 15:22:10

标签: python python-imaging-library eyed3

我正在尝试使用枕头下载图像,然后将该图像提供给eyed3用作专辑封面,但出现以下错误:

TypeError: can't concat JpegImageFile to bytes

        response = requests.get(album_art_url)
        img = Image.open(BytesIO(response.content))
            audiofile = eyed3.load(f"{self.current_song_name}-{self.current_song_url}.mp3")
            audiofile.tag.images.set(type_=3, img_data=img,
                                     mime_type="image/jpeg",
                                     description=None, 
                                     img_url=None)
            audiofile.tag.save()

1 个答案:

答案 0 :(得分:0)

根据此处的答案尝试此解决方案 How to set thumbnail for mp3 using eyed3 python module?

import eyed3
import urllib.request

audiofile = eyed3.load(f"{self.current_song_name}-{self.current_song_url}.mp3")

audiofile.initTag(version=(2, 3, 0))  # version is important
response = urllib.request.urlopen(album_art_url)
imagedata = response.read()
audiofile.tag.images.set(3, imagedata, "image/jpeg", u"cover")
audiofile.tag.save()