Support multiple songs with the same name

This commit is contained in:
Mikko Ahlroth 2021-01-09 23:02:42 +02:00
parent f68750ade6
commit 6658f509e6

View file

@ -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)