Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #!/usr/bin/env python
 - import os
 - import glob
 - import shutil
 - import mutagen
 - from sys import exit
 - musicdir = raw_input("What directory are the music files located in? : ")
 - musfile = glob.glob(musicdir + '/' + "*.mp3")
 - musfile1 = glob.glob(musicdir + '/' + "*.flac")
 - musfile.extend(musfile1)
 - newmusicdir = raw_input("What directory should the music files be organized into? : ")
 - done = False
 - while not done:
 - for m in musfile:
 - if musfile:
 - try:
 - musta = mutagen.File(m, easy=True)
 - mar = str(musta['artist'][0])
 - mal = str(musta['album'][0])
 - mti = str(musta['title'][0])
 - mtr = str(musta['tracknumber'][0])
 - os.makedirs(newmusicdir + '/' + mar + '/' + mal + '/')
 - except OSError:
 - pass
 - finally:
 - try:
 - if m.endswith('.mp3'):
 - os.rename(m,mtr + ' - ' + mar + ' - ' + mti + '.mp3')
 - m =mtr + ' - ' + mar + ' - ' + mti + '.mp3'
 - shutil.move(m,newmusicdir + '/' + mar + '/' + mal + '/')
 - elif m.endswith('.flac'):
 - os.rename(m,mtr + ' - ' + mar + ' - ' + mti + '.flac')
 - m = mtr + ' - ' + mar + ' - ' + mti + '.flac'
 - shutil.move(m,newmusicdir + '/' + mar + '/' + mal + '/')
 - elif not musfile:
 - print "Looks like we're done here. Please press <enter> to exit"
 - raw_input()
 - sys.exit(0)
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment