环境
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
pip3 --version
pip 19.2.3
pip3 install eyed3
借助eyed3模块还实现,执行前需要安装libmagic的DLL.。pip3 install python-magic-bin==0.4.14
eyed3读取文件的时候,发现中文文件名报错,但是改成数字或者英文名正常,所以有个替换文件名的操作。
# -*- coding: utf-8 -*-
import eyed3
import os
import operator
prefix=r".mp3"
path=r"C:\Users\f\Desktop\神奇\后续的"
for eachfile in os.listdir(path):
length=len(eachfile)
if operator.eq(prefix,eachfile[length-4:length])==True:
title=u""+eachfile[0:length-4]
print(title)
print(eachfile)
track_num=eachfile[0:eachfile.find('.')]
print(track_num)
newname=str(track_num)+".mp3"
os.rename(os.path.join(path,eachfile), os.path.join(path, newname))
audiofile=eyed3.load(newname)
audiofile.initTag()
audiofile.tag.album = u"神奇"
audiofile.tag.track_num =int(track_num)
audiofile.tag.title =title
audiofile.tag.album_artist = u"故事"
audiofile.tag.save()
os.rename(os.path.join(path,newname), os.path.join(path, eachfile))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)