Modify metadata of mp3 files using mutagen.
最近通过截取音频的方式截取了好几段音乐,想修改mp3文件的metadata,包括但不限于
artist | 王菲 |
title | 如愿 |
album | 忘了 |
import os
import numpy as np
from mutagen.easyid3 import EasyID3
filename='王菲 - 如愿.mp3'
audiofile = EasyID3(filename)
audiofile['artist'] = '王菲'
audiofile['title'] = '如愿'
audiofile['album'] = '忘了'
audiofile.save()
效果:
mutagen包地址
https://github.com/quodlibet/mutagen/tree/master/docs
使用方法参考源代码
可能用到的读取文件夹
# modifymeta.py
import os
from turtle import title
import numpy as np
from mutagen.easyid3 import EasyID3
cur_dir=os.getcwd()
mp3_list=os.listdir()
for filename in mp3_list:artist_name=filename.partition(' - ')[0]title_name=filename.partition(' - ')[2].partition('.')[0]if filename.partition(' - ')[2].partition('.')[2] !='mp3':continueaudiofile = EasyID3(filename)audiofile['artist'] = artist_nameaudiofile['album'] = '??'audiofile['title'] = title_nameaudiofile.save()