首先我进入了python的第三库安装的网站
https://pypi.org/project/eyeD3/
目前最新版:eyeD3 0.8.10
pip install eyeD3
pip install python-magic-bin==0.4.14
不执行这一句会报错的。eyeD3环境因为他整了好久。坑死了。
下面给网上安装问题总结:
pip install msgpack
#不安装会报错distributed 1.21.8 requires msgpack, which is not installed.
pip install python-magic-bin==0.4.14
#不安装,在import eyed3时会报错ImportError: failed to find libmagic. Check your installation
pip install eyeD3
实际安装3个包eyeD3-0.8.7 pathlib-1.0.1 python-magic-0.4.15
版权声明:本文为CSDN博主「优绎」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/YeoYi/article/details/80880639
$ eyeD3 song.mp3
song.mp3 [ 3.06 MB ]
-------------------------------------------------------------------------
ID3 v2.4:
title: Hollow
artist: Integrity
album: Humanity Is The Devil
album artist: None
track: 2
-------------------------------------------------------------------------
看到官网的示例,我也照做了,但是没有成功过,经过反复尝试和官网的对比发现。
路径包含空格,我用“”双引号括起来他不识别,同时路径包含中文也不识别。
如下:
C:\Users\mabh>eyeD3 "C:\Users\mabh\Desktop\tingChinaDownLoad\ 大话刘罗锅_郭德纲002正午唱曲声_郭德纲.mp3"
Nothing to do
C:\Users\mabh>eyeD3 "C:\Users\mabh\Desktop\tingChinaDownLoad\郭德纲002正午唱曲声_郭德纲.mp3"
Nothing to do
C:\Users\mabh>eyeD3 C:\Users\mabh\Desktop\tingChinaDownLoad\郭德纲002正午唱曲声_郭德纲.mp3
Nothing to do
C:\Users\mabh>eyeD3 C:\Users\mabh\Desktop\tingChinaDownLoad\001.mp3
...C:\Users\mabh\Desktop\tingChinaDownLoad\001.mp3[ 4.28 MB ]
-------------------------
Time: 18:46 MPEG2, Layer III [ 32 kb/s @ 22050 Hz - Mono ]
-------------------------
ID3 v2.4:
title: 大话刘罗锅 010三伏买鸡蛋
artist: 郭德纲
album: 大话刘罗锅
track:
-------------------------
1.路径包含空格,所以我必须得用双引号括起来要不然 就是两条命令语句了
2.我去掉 空格 还是不行。
3.既然去掉了空格,我尝试把双引号去掉,但是结果还是不行。
4.我把中文歌曲文件名重命名。结果成功了
总结:我也不知道为啥,反正就是不能有空格,不能有中文。
到这既然成功了,我可以愉快的用Python使用eyeD3修改歌曲元数据了
下面是官网示例:
import eyed3
audiofile = eyed3.load("song.mp3")
audiofile.tag.artist = u"Integrity"
audiofile.tag.album = u"Humanity Is The Devil"
audiofile.tag.album_artist = u"Integrity"
audiofile.tag.title = u"Hollow"
audiofile.tag.track_num = 2
audiofile.tag.save()
相信你一看就明白了。
用命令行报错了,我想用python试下果然也报错了。
下面是错误的代码实例:
import eyed3
path = r'C:\Users\mabh\Desktop\tingChinaDownLoad\ 大话刘罗锅_郭德纲010三伏买鸡蛋_郭德纲.mp3'
audiofile = eyed3.load(path)
audiofile.tag.title = u"郭德纲 相声"
audiofile.tag.save()
Traceback (most recent call last):
File "E:/PycharmProjects/HelloWorld/dada.py", line 7, in
audiofile.tag.title = u"郭德纲 相声"
AttributeError: 'NoneType' object has no attribute 'tag'
audiofile 没有返回任何东西。
尝试把文件名改下,执行试下。
也就是是这样:
path = r'C:\Users\mabh\Desktop\tingChinaDownLoad\010.mp3'
感觉不会出错了,但还是出错了。
raceback (most recent call last):
File "E:\Program Files\JetBrains\PyCharm 2019.2\helpers\pydev\pydevd.py", line 2060, in <module>
main()
File "E:\Program Files\JetBrains\PyCharm 2019.2\helpers\pydev\pydevd.py", line 2054, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "E:\Program Files\JetBrains\PyCharm 2019.2\helpers\pydev\pydevd.py", line 1405, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "E:\Program Files\JetBrains\PyCharm 2019.2\helpers\pydev\pydevd.py", line 1412, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "E:\Program Files\JetBrains\PyCharm 2019.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:/PycharmProjects/HelloWorld/dada.py", line 8, in <module>
audiofile.tag.save()
File "E:\Program Files\Python37\lib\site-packages\eyed3\id3\tag.py", line 826, in save
self._saveV2Tag(version, encoding, max_padding)
File "E:\Program Files\Python37\lib\site-packages\eyed3\id3\tag.py", line 1035, in _saveV2Tag
max_padding)
File "E:\Program Files\Python37\lib\site-packages\eyed3\id3\tag.py", line 951, in _render
raw_frame = f.render()
File "E:\Program Files\Python37\lib\site-packages\eyed3\id3\frames.py", line 298, in render
self.text.encode(id3EncodingToString(self.encoding)))
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-2: ordinal not in range(256)
看报错信息分析可能是编码问题。我的代码跟中文有关系只有这一行
audiofile.tag.title = u"郭德纲 相声"
告诉你,跟编码没关系。反正我的不是,查找资料得知,缺少调用函数
import eyed3
path = r'C:\Users\mabh\Desktop\tingChinaDownLoad\010.mp3'
audiofile = eyed3.load(path)
audiofile.initTag();
audiofile.tag.title = u"郭德纲 相声"
audiofile.tag.save()
audiofile.initTag(); 就是这句!!!!