Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 29th, 2010  |  syntax: Python  |  size: 1.33 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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