Advertisement
Guest User

Untitled

a guest
May 5th, 2011
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import os
  3. import glob
  4. import shutil
  5. import mutagen
  6. from sys import exit
  7.  
  8. musicdir = raw_input("What directory are the music files located in? : ")
  9. musfile = glob.glob(musicdir + '/' + "*.mp3")
  10. musfile1 = glob.glob(musicdir + '/' + "*.flac")
  11. musfile.extend(musfile1)
  12. newmusicdir = raw_input("What directory should the music files be organized into? : ")
  13.  
  14.  
  15. done = False
  16.  
  17. while not done:
  18.     for m in musfile:
  19.         if musfile:
  20.             try:
  21.                 musta = mutagen.File(m, easy=True)
  22.                 mar = str(musta['artist'][0])
  23.                 mal = str(musta['album'][0])
  24.                 mti = str(musta['title'][0])
  25.                 mtr = str(musta['tracknumber'][0])
  26.                 os.makedirs(newmusicdir + '/' + mar + '/' + mal + '/')
  27.             except OSError:
  28.                 pass
  29.             finally:
  30.                 try:
  31.                     if m.endswith('.mp3'):
  32.                         os.rename(m,mtr + ' - ' + mar + ' - ' + mti + '.mp3')
  33.                         m =mtr + ' - ' + mar + ' - ' + mti + '.mp3'
  34.                         shutil.move(m,newmusicdir + '/' + mar + '/' + mal + '/')
  35.                     elif m.endswith('.flac'):
  36.                         os.rename(m,mtr + ' - ' + mar + ' - ' + mti + '.flac')
  37.                         m = mtr + ' - ' + mar + ' - ' + mti + '.flac'
  38.                         shutil.move(m,newmusicdir + '/' + mar + '/' + mal + '/')
  39.         elif not musfile:
  40.                 print "Looks like we're done here. Please press <enter> to exit"
  41.                 raw_input()
  42.                 sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement