我已经编写了一个小脚本,将我所有的.flac文件从dap移动到Artister子文件夹,以便从计算机上轻松访问。我在Ubuntu上使用了python3和诸如eyed3和os之类的libs。而且它在近30首歌曲(2位艺术家)中表现良好。 下面是代码:
import os
import eyed3
os.chdir("/home/user/Music")
cwd = os.getcwd()
# print the current directory
print("Current working directory is:", cwd)
listOfFiles = os.listdir()
artists = []
# print(listOfFiles)
try:
for file in listOfFiles:
aFile = eyed3.load(file)
artist = aFile.tag.artist
if artist not in a:
artists.append(artist)
os.mkdir(artist)
os.rename(cwd + '/' + file, cwd + '/' + artist + '/' + file)
except:
print("not a file")
print(artists)
它创建了两个文件夹。 但当我试图在我的Windows PC上运行此脚本时,它抛出了一个异常并打印“不是文件”。 以下是不带try/except的控制台输出:
Traceback (most recent call last):
File "D:\GitHub\Song-Sorter\main.py", line 21, in <module>
artist = aFile.tag.artist
AttributeError: 'NoneType' object has no attribute 'tag'
所以我尝试了这个(在artist = aFile.tag.artist
之后的下一行):
print(type(artist))
其输出为:
<class 'NoneType'>
有什么问题?不明白
找到了解决办法。我在图书馆的mp3部分测试了这个脚本,效果很好。然后我尝试了flac部分,但它不起作用,因为eyed3只适用于mp3。所以我建议使用诱变剂库
相关问题 更多 >
编程相关推荐