How to add album art to mp3 file using python 3?

二次信任 提交于 2019-12-12 12:15:23

问题


I was wondering what module to use for setting an image as the album art for a particular mp3 file. Mutagen seemed to be a popular choice, but it doesn't seem to work on python 3 and I can't find any documentation.


回答1:


Here's a modified version of the code I use. You will want to change the example.mp3 and cover.jpg (and perhaps the mime type too):

import eyed3

audiofile = eyed3.load('example.mp3')
if (audiofile.tag == None):
    audiofile.initTag()

audiofile.tag.images.set(3, open('cover.jpg','rb').read(), 'image/jpeg')

audiofile.tag.save()

tag.images.set() takes three arguments:

  • Picture Type: This is the type of image it is. 3 is the code for the front cover art. You can find them all here.
  • Image Data: This is the binary data of your image. In the example, I load this in using open().read().
  • Mime Type: This is the type of file the binary data is. If it's a jpg file, you'll want image/jpeg, and if it's a png file, you'll want image/png.


来源:https://stackoverflow.com/questions/38510694/how-to-add-album-art-to-mp3-file-using-python-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!