Skip to content Skip to sidebar Skip to footer

How To Set Thumbnail For Mp3 Using Eyed3 Python Module?

I can't set image thumbnails for mp3 files using eyed3 module in Python. I try next script: import eyed3 from eyed3.id3.frames import ImageFrame th = 'url_to_my_pic' file = 'to_mp

Solution 1:

After several hours learning of eyeD3, googling and experimenting with file cover, I think, I have a solution for you.

You need to follow these rules:

  • use ID3v2.3 (not v2.4 as by default in eyeD3);
  • add right description for cover image (word cover);
  • pass image as binary;

I'll give you an example of code, which works fine on my Windows 10 (should works on other platforms as well):

import eyed3
import urllib.request

audiofile = eyed3.load("D:\\tmp\\tmp_mp3\\track_example.mp3")

audiofile.initTag(version=(2, 3, 0))  # version is important
# Other data for demonstration purpose only (from docs)
audiofile.tag.artist = "Token Entry"
audiofile.tag.album = "Free For All Comp LP"
audiofile.tag.album_artist = "Various Artists"
audiofile.tag.title = "The Edge"

# Read image from local file (for demonstration and future readers)
with open("D:\\tmp\\tmp_covers\\cover_2021-03-13.jpg", "rb") as image_file:
    imagedata = image_file.read()
audiofile.tag.images.set(3, imagedata, "image/jpeg", u"cover")
audiofile.tag.save()

# Get image from the Internet
response = urllib.request.urlopen("https://example.com/your-picture-here.jpg")
imagedata = response.read()
audiofile.tag.images.set(3, imagedata, "image/jpeg", u"cover")
audiofile.tag.save()

Credits: My code is based on several pages: 1, 2, 3


Post a Comment for "How To Set Thumbnail For Mp3 Using Eyed3 Python Module?"