【问题标题】:TypeError: can't concat JpegImageFile to bytesTypeError:无法将 JpegImageFile 连接到字节
【发布时间】:2020-03-10 14:45:09
【问题描述】:

我正在尝试使用枕头下载图像,然后将该图像提供给 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()

【问题讨论】:

标签: python python-imaging-library eyed3


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-05-02
    • 1970-01-01
    • 2019-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多