Skip to content

Instantly share code, notes, and snippets.

@mhornbacher
Created March 31, 2017 19:46
Show Gist options
  • Save mhornbacher/fc87865b1eeb8ea3e9dd18969694a83c to your computer and use it in GitHub Desktop.
Save mhornbacher/fc87865b1eeb8ea3e9dd18969694a83c to your computer and use it in GitHub Desktop.
A small self contained python script to standardize with either .MP3 or .mp3. Replaces text in mp3 filenames as well
import os
from os.path import join
from tkinter import *
from tkinter import messagebox
def replace(subdir, string1, string2):
cwd = os.getcwd()
location = join(cwd, subdir)
for file in os.listdir(location):
os.rename(join(location, file), join(location, file.replace(string1, string2)))
def upper(event):
try:
replace(subdir.get(), from_entry.get(), to_entry.get())
replace(subdir.get(), ".mp3", ".MP3")
except FileNotFoundError:
messagebox.showerror("Error", "Sub Directory does not exist")
def lower(event):
try:
replace(subdir.get(), from_entry.get(), to_entry.get())
replace(subdir.get(), ".MP3", ".mp3")
except FileNotFoundError:
messagebox.showerror("Error", "Sub Directory does not exist")
root = Tk()
root.title("MP3 Editor")
frame = Frame(root, relief='flat', borderwidth=25)
Label(frame, text="""Welcome to MP3 Fixer
Press Make upper to transform .mp3 to .MP3
Enter any text into the boxes below to replace it at the same time.
(Current = {})
""".format(os.getcwd())).grid(row=0, columnspan=3)
Label(frame, text="SubDirectory (Blank For current)").grid(row=1, sticky=W, padx=4)
subdir = Entry(frame)
subdir.grid(row=1, column=1, columnspan=2, sticky=E, pady=4)
Label(frame, text="Initial Text").grid(row=2, sticky=W, padx=4)
from_entry = Entry(frame)
from_entry.grid(row=2, column=1, columnspan=2, sticky=E, pady=4)
Label(frame, text="Replacement Text").grid(row=3, sticky=W, padx=4)
to_entry = Entry(frame)
to_entry.grid(row=3, column=1, columnspan=2, sticky=E, pady=4)
make_upper = Button(frame, text="Make Upper")
make_upper.bind("<Button-1>", upper)
make_upper.grid(row=4, column=0, pady=15)
make_lower = Button(frame, text="Make Lower")
make_lower.bind("<Button-1>", lower)
make_lower.grid(row=4, column=1, padx=4)
frame.pack()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment