Created
September 1, 2012 14:14
-
-
Save danielpclark/3574354 to your computer and use it in GitHub Desktop.
GRips MP3 Renamer - Take the default naming structure from grip and rename mp3s to Artist - Song.mp3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Grips MP3 Renamer (GMR) | |
Author: Daniel P. Clark. | |
2-11-2002 | |
STABLE 0.0.1 | |
""" | |
# I wrote this because I had already copied a bunch of cds to my computer with grip | |
# and the files were all just the song name, in lower case, without spaces, and in directories | |
# for the band name, then the albumn | |
# | |
# this script right here will take the band name directory (which is 2 levels up from mp3) | |
# and put it on the front of the mp3, replacing all underscores with spaces, and capitalizing each word | |
import os, sys, string | |
# USER MUST DEFINE BASE OF MP3 TREE, EXACTLY 2 DIRECTORIES DOWN FROM MP3 DIRS | |
# e.g. /usr/media/mp3/cd/artist/albumn/mp3s.mp3 | |
# you would use for base dir /usr/media/mp3/cd/ | |
BASE = "/usr/media/mp3/cd/" | |
FILEEXT = ".mp3" | |
def main(): | |
AUTORENAME = 0 | |
if "-a" in sys.argv[1:] or "-auto" in sys.argv[1:]: | |
AUTORENAME = 1 | |
os.system("clear") | |
print "Grips MP3 Renamer (ver 0.0.1)" | |
print "Author: Daniel P. Clark" | |
os.chdir(BASE) | |
LSTDIR2 = os.listdir(".") | |
for x in range(len(LSTDIR2)): | |
if os.path.isdir(os.path.abspath(".")+os.sep+LSTDIR2[x]): | |
os.chdir(os.path.abspath(".")+os.sep+LSTDIR2[x]) | |
LSTDIR3 = os.listdir(".") | |
for y in range(len(LSTDIR3)): # gets to the mp3s here | |
if os.path.isdir(os.path.abspath(".")+os.sep+LSTDIR3[y]): | |
os.chdir(os.path.abspath(".")+os.sep+LSTDIR3[y]) | |
CDL = os.listdir(".") # Current Directory List | |
OCDL = CDL[:] # for old file name | |
ABSP = os.path.abspath(".") # Absolute Path | |
ABSPL = string.split(ABSP, os.sep)[1:] # list of path dir names | |
ABSPL[-2] = string.replace(ABSPL[-2], "_", " ") # for band name (replaces underscore with space) | |
for z in range(len(CDL)): | |
NR = 0 | |
if string.find(CDL[z], " ") == -1 and string.lower(CDL[z][-4:]) == FILEEXT: # if the file does not have a space in its name, and is FILE wanted | |
CDL[z] = string.replace(CDL[z], "_", " ") # replace all underscores with spaces | |
NFN = ABSPL[-2] + " - " + CDL[z] # new file name | |
NFN = string.capwords(NFN) | |
print string.center("***Renaming***",79) | |
print "From:\t| "+OCDL[z]+" |\n To:\t| "+NFN+" |\n(y/n a/auto q/quit t/type)\nContinue? ", | |
if not AUTORENAME: | |
Prompt = raw_input() | |
else: | |
Prompt = "y" | |
if string.lower(Prompt) in ("t", "type"): # type the full file name manually | |
NFN = raw_input("Please enter full file name: ") | |
Prompt = "y" | |
if string.lower(Prompt) in ("y", "yes"): | |
os.rename(OCDL[z],NFN) # rename original file to new file name | |
print "DONE!\n" | |
elif string.lower(Prompt) in ("n", "no"): | |
pass | |
NR = 1 | |
elif string.lower(Prompt) in ("a", "auto"): | |
AUTORENAME = 1 | |
elif string.lower(Prompt) in ("q", "quit"): | |
sys.exit() | |
else: | |
NR = 1 | |
if not NR: | |
print "\""+OCDL[z]+"\" was succesfully renamed to\n", NFN | |
else: | |
print OCDL[z], "was NOT renamed!" | |
os.chdir("..") | |
os.chdir("..") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment