我试图弄清楚如何根据从 mp3 文件中按 Artist>Album> 提取的 ID3 标签创建目录(这里需要是实际的 .mp3 文件)?
到目前为止,我的 ID3 标签存储在 pandas 数据框中,并且我为第一位艺术家创建了一个目录。到目前为止,这是我的代码:
import pandas as pd
from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3
import pathlib
import os
def createFolder(directory):
try:
os.makedirs(directory)
except OSError:
print ('Error: Creating directory. ' + directory)
def createArtist(df,path):
artist_list = list(df.artist)
for i in artist_list:
os.makedirs(path+str(i))
artist_df = df.loc[df['artist'] == i]
audio = MP3("Skepta - Shutdown.mp3", ID3=EasyID3)
df = pd.DataFrame(columns = audio.keys())
a = (list(pathlib.Path('H:/').glob('*.mp3')))
createFolder('./Music Library/')
###this updates the dataframe with ID3 tags for each .mp3 file in H:/
for i in range(1,len(a)):
audio=MP3(a[i],ID3=EasyID3)
df.loc[i] = audio.values()
print(df)
path ='/Music Library/'
createArtist(df,path)