批次改MP3資訊

我爱你的發表於2024-04-06
import os
import re

import eyed3 as eyed3
path = 'D:\\歌曲\\改真無損\data\\'#歌曲目錄

"""
改MP3資訊 參考內容https://www.cnblogs.com/yanzhen/p/14014999.html https://www.cnblogs.com/jaysonteng/p/12312828.html
"""

files = os.listdir(path) # 獲得目錄中所有檔案
l = 0
for item in files:
if item.endswith('.mp3') or item.endswith('.mp4'):
item_path = path + item
print(item_path)
if re.findall(rf'.(.*?) -', item):
song_auth = re.findall(rf'.(.*?) -', item)[0].split('.')[1]
elif re.findall(rf'.(.*?)-', item):
song_auth = re.findall(rf'.(.*?)-', item)[0].split('.')[1]
else:
pass
if re.findall(rf'- (.*?).mp', item):
song_name = re.findall(rf'- (.*?).mp', item)[0].replace('\n', '').replace('\r', '')
else :
song_name = re.findall(rf'-(.*?).mp', item)[0].replace('\n', '').replace('\r', '')
audiofile = eyed3.load(item_path)
audiofile.initTag()
audiofile.tag.artist = u"{}".format('song_auth22') # 參與創作的藝術家
audiofile.tag.album_artist = u"{}".format('song_auth22') # 唱片藝術家
audiofile.tag.title = u"{}".format(song_name) # 標題不是檔名稱
audiofile.tag.save()
print(song_auth,song_name)
l =l+1
print(l)


相關文章