|
@ -17,14 +17,11 @@ def __usage(): |
|
|
|
|
|
|
|
|
def yesno(prompt): |
|
|
def yesno(prompt): |
|
|
while True: |
|
|
while True: |
|
|
answer = input("{} [yn](append * to remember) ".format(prompt)).strip().lower() |
|
|
answer = input("{} [yn] ".format(prompt)) |
|
|
remember = (answer[-1] == "*") |
|
|
if answer.strip().lower() == "y": |
|
|
if remember: |
|
|
return True |
|
|
answer = answer[0:-1] |
|
|
if answer.strip().lower() == "n": |
|
|
if answer == "y": |
|
|
return False |
|
|
return True, remember |
|
|
|
|
|
if answer == "n": |
|
|
|
|
|
return False, remember |
|
|
|
|
|
|
|
|
|
|
|
def confirm(destname): |
|
|
def confirm(destname): |
|
|
return yesno("File '{}' already exist. Overwrite?".format(destname)) |
|
|
return yesno("File '{}' already exist. Overwrite?".format(destname)) |
|
@ -53,19 +50,15 @@ if __name__ == "__main__": |
|
|
) |
|
|
) |
|
|
sys.exit(1) |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
remember = False |
|
|
|
|
|
for file in song_files: |
|
|
for file in song_files: |
|
|
song = song_parsers[source]("", file, DEFAULT_CONFIG) |
|
|
song = song_parsers[source]("", file, DEFAULT_CONFIG) |
|
|
try: |
|
|
try: |
|
|
destname = "{}.{}".format(".".join(file.split(".")[:-1]), dest) |
|
|
destname = "{}.{}".format(".".join(file.split(".")[:-1]), dest) |
|
|
dest_exists = os.path.exists(destname) |
|
|
if os.path.exists(destname): |
|
|
if dest_exists and not remember: |
|
|
if not confirm(destname): |
|
|
overwrite, remember = confirm(destname) |
|
|
|
|
|
if dest_exists and not overwrite: |
|
|
|
|
|
continue |
|
|
continue |
|
|
converted = song.render(dest) |
|
|
|
|
|
with open(destname, "w") as destfile: |
|
|
with open(destname, "w") as destfile: |
|
|
destfile.write(converted) |
|
|
destfile.write(song.render(dest)) |
|
|
|
|
|
|
|
|
except NotImplementedError: |
|
|
except NotImplementedError: |
|
|
LOGGER.error("Cannot convert to format '%s'.", dest) |
|
|
LOGGER.error("Cannot convert to format '%s'.", dest) |
|
|