如何使用python 3将专辑封面添加到mp3文件? [英] How to add album art to mp3 file using python 3?

查看:569
本文介绍了如何使用python 3将专辑封面添加到mp3文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用哪个模块将图像设置为特定mp3文件的专辑封面. Mutagen似乎是一个受欢迎的选择,但它似乎不适用于python 3,并且我找不到任何文档.

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.

推荐答案

这是我使用的代码的修改版本.您将需要更改example.mp3cover.jpg(也许还有mime类型):

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()带有三个参数:

  • 图片类型:这是图片的类型. 3是封面插图的代码.您可以在此处全部找到.
  • 图像数据:这是图像的二进制数据.在示例中,我使用open().read()加载此代码.
  • MIME类型:这是二进制数据的文件类型.如果是jpg文件,则需要image/jpeg;如果是png文件,则需要image/png.
  • 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.

这篇关于如何使用python 3将专辑封面添加到mp3文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆