我正在尝试编写代码来组织 +40G 的音乐,我想按艺术家进行组织,到目前为止,我已经能够获取艺术家信息,但我正在为每个艺术家创建一个目录并拥有与同一个艺术家进入同一个目录,而不是为每首歌创建一个单独的目录。
import os #imports os functions
import eyed3 #imports eyed3 functions
root_folder = '/Users/ntoscano/desktop/mp3-organizer'
files = os.listdir(root_folder) #lists all files in specified directory
if not files[1].endswith('.mp3'):
pass #if the file does not end with ".mp3" it does not load it into eyed3
for file_name in files:
#if file_name.endswith('.mp3'): continue #if file ends with ".mp3" it continues onto the next line
abs_location = '%s/%s' % (root_folder, file_name)
song_info = eyed3.load(abs_location) #loads each file into eyed3 and assignes the return value to song_info
if song_info is None:
print 'Skippig %s' % abs_location
continue
os.mkdir(os.path.expanduser('~/Desktop/mp3-organizer/%s')) % song_info.tag.artist
print song_info
print song_info.tag.artist
这是我到目前为止所拥有的,但它坏了,第 19 行总是给我一个错误,
Nicolass-MacBook-Air:mp3-organizer ntoscano$ python eyeD3test.py
Skippig /Users/ntoscano/desktop/mp3-organizer/.DS_Store
Traceback (most recent call last):
File "eyeD3test.py", line 19, in <module>
os.mkdir(os.path.expanduser('~/Desktop/mp3-organizer/%s')) % song_info.tag.artist
TypeError: unsupported operand type(s) for %: 'NoneType' and 'unicode'
我是编码新手,所以我确定这是一个简单的错误,但我只是不明白如何获得以艺术家信息为名称的目录。感谢任何帮助