Python:我如何使用Python访问mp3文件的元数据? [英] Python: How can I access an mp3 file's metadata using Python?

查看:144
本文介绍了Python:我如何使用Python访问mp3文件的元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想看艺术家的名字?或添加BPM信息?有什么Python的工具可以去做这件事吗?

解决方案

有一个名为 Python-ID3 正是如此。如果你使用的是Debian / Ubuntu的软件包,它的软件包名称是 python-id3 ,并且在它的网站上有一个示例代码:

  from ID3 import * 
try:
id3info = ID3('/ some / file / moxy.mp3')
print id3info $
id3info ['TITLE'] =绿色鸡蛋和火腿
id3info ['ARTIST'] =MoxyFrüvous
for k,v in id3info.items():
打印k,:,v
,除了InvalidTagError,消息:
打印无效的ID3标签:,消息


Supposing I wanted to see the Artist Name? Or add BPM information? What Python tools could I go about doing this?

解决方案

There's a module called Python-ID3 that does exactly this. If you're on a Debian/Ubuntu box, its package name is python-id3 and there is example code on its website:

from ID3 import *
try:
    id3info = ID3('/some/file/moxy.mp3')
    print id3info
    id3info['TITLE'] = "Green Eggs and Ham"
    id3info['ARTIST'] = "Moxy Früvous"
    for k, v in id3info.items():
        print k, ":", v
except InvalidTagError, message:
    print "Invalid ID3 tag:", message

这篇关于Python:我如何使用Python访问mp3文件的元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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