+ 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'
私はコーディングに慣れていないので、それは単純なエラーだと確信していますが、アーティスト情報を名前として作成したディレクトリを取得する方法がわかりません。どんな助けでも感謝されます