22
33import os
44import re
5+ import shutil
56import sys
67from mutagen .easyid3 import EasyID3
78
8- emptyChars = re .compile (r"[(),.'\\\?]" )
9+ emptyChars = re .compile (r"[(),.'\\\?\# ]" )
910def toNeat (s ):
1011 s = s .lower ().replace (" " , "-" ).replace ("&" , "and" )
1112 s = emptyChars .sub ("" , s )
@@ -15,16 +16,20 @@ def toNeat(s):
1516 sys .exit (- 42 )
1617 return s
1718
19+ delete_dirs = []
1820for dirname , dirnames , filenames in os .walk ('.' ):
1921 # Move all the files to the root directory.
2022 for filename in filenames :
2123 ext = os .path .splitext (filename )[1 ]
2224 if ext == ".mp3" :
2325 fullPath = os .path .join (dirname , filename )
2426 print ("file: " + str (fullPath ))
25- audio = EasyID3 (fullPath )
26- title = audio ['title' ][0 ].decode ()
27- print (" title: " + title )
27+
28+ try :
29+ audio = EasyID3 (fullPath )
30+ title = audio ['title' ][0 ].decode ()
31+ print (" title: " + title )
32+ except : title = None
2833
2934 if not title :
3035 print ("Error: title not found for '" + filename + "'" )
@@ -51,6 +56,9 @@ def toNeat(s):
5156
5257 # Delete all subdirectories.
5358 for subdirname in dirnames :
54- os .rmdir (subdirname )
59+ delete_dirs .append (subdirname )
60+
61+ for d in delete_dirs :
62+ shutil .rmtree (d ,ignore_errors = True )
5563
5664print ("\n Complete!" )
0 commit comments