Skip to content

Commit

Permalink
Added better cleanup to catch invalid directory characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBengineer committed May 19, 2021
1 parent 80d5dcb commit 7c390ab
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7c390ab

Please sign in to comment.