All pastes #983881 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-04-13 18:33 UTC
rendered paste body
from easygui import *
from mutagen.easyid3 import EasyID3
import os

directory = diropenbox(title="Pick the directory in which you would like to organize")
os.chdir(directory)

for filename in os.listdir(os.getcwd()):
    extension = os.path.splitext(filename)
    extension = extension[1]
    if extension == ".mp3":
        audio = EasyID3(filename)
        artist = audio["artist"]
        title = audio["title"]
        artist = artist[0]
        title = title[0]
        new_filename = artist + " - " + title + ".mp3"
        new_filename = new_filename.replace(":", " ")
        new_filename = new_filename.replace("?", " ")
        if new_filename != filename:
            os.rename(filename, new_filename)
    else:
        print filename + " is not a mp3 file!"