Advertisement
Peaser

Trackrenamer

Apr 25th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import eyed3, os
  2. def main():
  3.   print "Track Renamer"
  4.   directory = "songs/" # Assuming "songs" in current directory
  5.   for fnum, file in enumerate(os.listdir(directory)):
  6.     print "\t[%d] - Changing: %s" % (fnum, file)
  7.     if (os.path.isfile(directory+file)) and (file.endswith(".mp3")):
  8.         song = eyed3.load(directory+file)
  9.         try:
  10.           data = os.path.splitext(file)[0].split(" - ")
  11.           song.tag.artist = unicode(data[0])
  12.           song.tag.title  = unicode(data[1])
  13.           song.tag.save()
  14.           print "\t[{0}] - Verifying... Artist: '{1}', Track: '{2}'.".format(fnum,song.tag.artist,song.tag.title)
  15.         except:
  16.           print "\t[{0}] - {1} is Nonetype. Skipping...".format(fnum, os.path.splitext(file)[0])
  17. if __name__ == '__main__':
  18.   main()
  19.   os.system("pause")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement