Support multiple songs with the same name
This commit is contained in:
parent
f68750ade6
commit
6658f509e6
1 changed files with 10 additions and 0 deletions
10
convert.py
10
convert.py
|
@ -40,6 +40,7 @@ output_path = cli_args.output
|
||||||
print(f"Converting {csv_file} to path {output_path}...", file=sys.stderr)
|
print(f"Converting {csv_file} to path {output_path}...", file=sys.stderr)
|
||||||
|
|
||||||
with open(csv_file) as csv_handle:
|
with open(csv_file) as csv_handle:
|
||||||
|
processed_songs = set()
|
||||||
reader = csv.reader(csv_handle, delimiter=delim_char, quotechar=quote_char)
|
reader = csv.reader(csv_handle, delimiter=delim_char, quotechar=quote_char)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -79,8 +80,17 @@ with open(csv_file) as csv_handle:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
file_name = title.replace("/", "_")
|
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"
|
target_file = f"{output_path}/{file_name}.txt"
|
||||||
with open(target_file, mode="w") as target:
|
with open(target_file, mode="w") as target:
|
||||||
target.write(file_contents)
|
target.write(file_contents)
|
||||||
|
print(f"Wrote {target_file}", file=sys.stderr)
|
||||||
|
processed_songs.add(file_name)
|
||||||
|
|
||||||
print("\nDone!", file=sys.stderr)
|
print("\nDone!", file=sys.stderr)
|
||||||
|
|
Loading…
Reference in a new issue