Skip to content

Instantly share code, notes, and snippets.

@ma6174
Created January 18, 2014 13:57
Show Gist options
  • Save ma6174/8490913 to your computer and use it in GitHub Desktop.
Save ma6174/8490913 to your computer and use it in GitHub Desktop.
rename music using titie and artist
#!/usr/bin/env python
# coding=utf-8
import os
from mutagen.mp3 import MP3
from mutagen.easyid3 import EasyID3
dir = "/home/ma6174/Music/"
for i in os.listdir(dir):
real_path = dir + i
id3info = MP3(real_path, ID3=EasyID3)
new_name = id3info['title'][0] + '-' + id3info['artist'][0] + os.path.splitext(real_path)[1]
new_path = dir + new_name.replace('/','').replace(' ','')
print "rename", real_path, "==>", new_path
os.rename(real_path,new_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment