使用Python的eyed3库修改MP3 tag
2016-02-14 14:13
501 查看
下载了一些英语学习的MP3,用百度音乐播放,顺序是乱的,音乐播放器一般是显示tag中title的。此外还有一点,百度音乐播放如果碰到MP3的tag版本比较低的,比如1.0,则不是显示title,这点比较奇怪,不知道是什么原因。所以如果需要按照自己的需求来显示的话,需要修改两个地方,一个是版本号,一个是title。
下面代码中,audiofile.initTag()是用来修改版本号的(默认版本号是2.4),而audiofile.tag.title = unicode(id3)是用来修改title的,按照文件名来修改,就是文件名去掉.mp3就可以了。
另外需要注意的一点是,eyed3现在只支持python 2.6,python 2.7,暂不能用python 3.
下面是版本号。
eyed3.id3.ID3_V1 = (1, None, None)
Version 1, 1.0 or 1.1
eyed3.id3.ID3_V1_0 = (1, 0, 0)
Version 1.0, specifically
eyed3.id3.ID3_V1_1 = (1, 1, 0)
Version 1.1, specifically
eyed3.id3.ID3_V2 = (2, None, None)
Version 2, 2.2, 2.3 or 2.4
eyed3.id3.ID3_V2_2 = (2, 2, 0)
Version 2.2, specifically
eyed3.id3.ID3_V2_3 = (2, 3, 0)
Version 2.3, specifically
eyed3.id3.ID3_V2_4 = (2, 4, 0)
Version 2.4, specifically
eyed3.id3.ID3_DEFAULT_VERSION = (2, 4, 0)
The default version for eyeD3 tags and save operations.
下面代码中,audiofile.initTag()是用来修改版本号的(默认版本号是2.4),而audiofile.tag.title = unicode(id3)是用来修改title的,按照文件名来修改,就是文件名去掉.mp3就可以了。
另外需要注意的一点是,eyed3现在只支持python 2.6,python 2.7,暂不能用python 3.
#! /usr/bin/env python #coding utf-8 import os import re import sys import eyed3 if __name__ == "__main__": if len(sys.argv) != 2: # print('please input MP3 directory') exit() patemplate=r'\.mp3' repat=re.compile(patemplate) dir = sys.argv[1] for filename in os.listdir(dir): filepath = os.path.join(dir, filename) p = re.compile(r'(.*)-(.*)\.mp3', re.I) m = p.match(filename) if m: id3=filename id3 = repat.sub('', filename) audiofile = eyed3.load(filepath) audiofile.initTag() audiofile.tag.title = unicode(id3) audiofile.tag.artist = u"NCE2" audiofile.tag.album = u"NCE2" audiofile.tag.album_artist = u"NCE2" audiofile.tag.track_num = 0 audiofile.tag.comment=u"NCE2" audiofile.tag.save() else: pass
下面是版本号。
eyed3.id3.ID3_V1 = (1, None, None)
Version 1, 1.0 or 1.1
eyed3.id3.ID3_V1_0 = (1, 0, 0)
Version 1.0, specifically
eyed3.id3.ID3_V1_1 = (1, 1, 0)
Version 1.1, specifically
eyed3.id3.ID3_V2 = (2, None, None)
Version 2, 2.2, 2.3 or 2.4
eyed3.id3.ID3_V2_2 = (2, 2, 0)
Version 2.2, specifically
eyed3.id3.ID3_V2_3 = (2, 3, 0)
Version 2.3, specifically
eyed3.id3.ID3_V2_4 = (2, 4, 0)
Version 2.4, specifically
eyed3.id3.ID3_DEFAULT_VERSION = (2, 4, 0)
The default version for eyeD3 tags and save operations.
相关文章推荐
- ubuntu python2.7解决 UnicodeEncodeError: 'ascii' 支持utf8
- 如何编写bat脚本定时执行某python脚本
- python logging
- Python 路谱
- python绘制非常漂亮的图表
- python编程常用模板总结
- opencv+python学习笔记【1】开发环境配置
- Python 3.x - 一个简单的客户端Get请求程序
- python学习笔记-Day14 -css基础知识-part2
- python之xml文件处理的例子-问题描述及解决方法
- Windows下安装Python PIP
- python编码最佳实践之总结
- python 简单绘图
- python实现百度贴吧爬虫
- Python 中的浮点数
- python交互式文档计算格式
- python动态网页爬取——四六级成绩批量爬取
- Python在Console下显示文本进度条的方法
- Draw Picture With Python Matplotlib
- 【python笔记】python中的list、tuple、set、dict用法简析