Advertisement
Guest User

Untitled

a guest
May 29th, 2010
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1.     def traverse(self,directory):
  2.         """
  3.        Processes a filelist from findMP3s, building the musicLibrary from metadata.
  4.        """
  5.         u = Utils()
  6.         results = {}
  7.        
  8.         files = []
  9.        
  10.         for root, subFolders, file in os.walk(directory):
  11.             for f in file:
  12.                 if f.endswith(".mp3"):
  13.                     files.append(os.path.join(root,f))
  14.  
  15.        
  16.         for f in files:
  17.             filePath = os.path.join(directory, f)
  18.             try:
  19.                 audio = EasyID3(filePath)
  20.                 artist = unicode(audio["artist"][0])
  21.                 title = unicode(audio["title"][0])
  22.                 album = unicode(audio["album"][0])
  23.                
  24.                 if not results.has_key(artist):
  25.                     results[artist] = {}
  26.                 if not results[artist].has_key(album):
  27.                     results[artist][album] = []
  28.                 results[artist][album].append([filePath,title])
  29.                
  30.             except KeyError:
  31.                 print "MP3 missing artist, title or album: " + filePath
  32.             except EOFError:
  33.                 print "ID3 table corrupted: " + filePath
  34.             except IOError:
  35.                 print "IOError (UTF getting in the way): " + filePath
  36.                
  37.            
  38.         return results
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement