From 7c390ab32583eb14c1b6a36cadc2315f74f0016b Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 19 May 2021 13:35:45 -0400 Subject: [PATCH] Added better cleanup to catch invalid directory characters. --- main.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 516c4ab..20a32f2 100644 --- a/main.py +++ b/main.py @@ -9,14 +9,20 @@ from tkinter import filedialog -def cleanup(dirty_text): +def cleanup(dirty_text, replace_str="_"): if isinstance(dirty_text, str): clean = dirty_text.strip() - fix = [[":", "_"], - ["'", "_"], - ['"', "_"], - ["/", "_"], - [";", "_"], ] + fix = [[":", replace_str], + ["'", replace_str], + ['"', replace_str], + ["/", replace_str], + ["\\", replace_str], + ["?", replace_str], + ["*", replace_str], + ["<", replace_str], + [">", replace_str], + ["|", replace_str], + [";", replace_str], ] for a, b in fix: clean = clean.replace(a, b) return clean @@ -283,8 +289,8 @@ def status(l_time, current_index, l_index, total, process_start_time): artist = files_dict[filename]["tags"]["artist"] if artist and album: - artist_path = os.path.join(music_path, cleanup(artist)) - album_path = os.path.join(music_path, cleanup(artist), cleanup(album)) + artist_path = os.path.join(music_path, cleanup(artist, "")) + album_path = os.path.join(music_path, cleanup(artist, ""), cleanup(album, "")) if not os.path.exists(artist_path): os.mkdir(artist_path)