问题
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 wantimage/jpeg
, and if it's apng
file, you'll wantimage/png
.
来源:https://stackoverflow.com/questions/38510694/how-to-add-album-art-to-mp3-file-using-python-3