python实现MP3加封面图片,修改作者,专辑

python实现MP3加封面图片,修改作者,专辑

需要安装eyed3

#!/usr/bin/env python
# encoding: utf-8

import eyed3
import imghdr
from eyed3.id3.frames import ImageFrame

def saveMp3(mp3_path, img_path):
    """
    mp3文件修改属性
    :param mp3_path:
    :param img_path:
    :return:
    """
    audioFile = eyed3.load(path=mp3_path)
    # audioFile.tag.artist = u"五条人"
    # audioFile.tag.title = u"世界的理想"
    # audioFile.tag.album = u"乐队的夏天"
    audioFile.tag.artist = artist
    audioFile.tag.title = title
    audioFile.tag.album = album
    img_type = imghdr.what(img_path)
    audioFile.tag.images.set(ImageFrame.FRONT_COVER, open(img_path, 'rb').read(), 'image/' + img_type)
    # audioFile.tag.save()
    audioFile.tag.save(version=eyed3.id3.ID3_DEFAULT_VERSION, encoding='utf-8')

if __name__ == '__main__':
    saveMp3(mp3_path, img_path)

 出现过几个问题:

1. 根据变量设置tag时,中文无法解析返回的是“?”,所以在执行save 时需要添加参数

audioFile.tag.save(version=eyed3.id3.ID3_DEFAULT_VERSION, encoding='utf-8')

2. 设置图片时会出现图片没保存上,需要看下mp3的名称是否包含特殊字符(可能是特殊字符问题)

最后显示结果:

 问题参考:audio - How to add album art to mp3 file using python 3? - Stack Overflowhttps://stackoverflow.com/questions/38510694/how-to-add-album-art-to-mp3-file-using-python-3

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值