From 6658f509e67f4e27974235d3cbdb69c417d24d70 Mon Sep 17 00:00:00 2001 From: Mikko Ahlroth Date: Sat, 9 Jan 2021 23:02:42 +0200 Subject: [PATCH] Support multiple songs with the same name --- convert.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/convert.py b/convert.py index c42c522..d55c1c5 100755 --- a/convert.py +++ b/convert.py @@ -40,6 +40,7 @@ output_path = cli_args.output print(f"Converting {csv_file} to path {output_path}...", file=sys.stderr) with open(csv_file) as csv_handle: + processed_songs = set() reader = csv.reader(csv_handle, delimiter=delim_char, quotechar=quote_char) i = 0 @@ -79,8 +80,17 @@ with open(csv_file) as csv_handle: """ file_name = title.replace("/", "_") + if file_name in processed_songs: + orig_file_name = file_name + r = 0 + while file_name in processed_songs: + r += 1 + file_name = f"{orig_file_name}_{r}" + target_file = f"{output_path}/{file_name}.txt" with open(target_file, mode="w") as target: target.write(file_contents) + print(f"Wrote {target_file}", file=sys.stderr) + processed_songs.add(file_name) print("\nDone!", file=sys.stderr)