Awell00 commited on
Commit
dab1823
·
verified ·
1 Parent(s): 91157e1

fix: problem with function sanitize

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -17,10 +17,7 @@ INPUT_FOLDER = "input"
17
  download_path = ""
18
 
19
  def sanitize_filename(filename):
20
- match = re.match(r'^(.*? - .*?)(?: \[.*\]|\(.*\))?$', filename)
21
- formatted_title = match.group(1) if match else filename
22
-
23
- return sanitize_filename(formatted_title.strip())
24
 
25
  def delete_input_files(input_dir):
26
  wav_dir = Path(input_dir) / "wav"
@@ -33,7 +30,11 @@ def handle_file_upload(file):
33
  return None, "No file uploaded"
34
 
35
  filename = os.path.basename(file.name)
36
- formatted_title = sanitize_filename(Path(filename).stem)
 
 
 
 
37
 
38
  input_path = os.path.join(INPUT_FOLDER, "wav", f"{formatted_title}.wav")
39
  os.makedirs(os.path.dirname(input_path), exist_ok=True)
 
17
  download_path = ""
18
 
19
  def sanitize_filename(filename):
20
+ return re.sub(r'[\\/*?:"<>|]', '_', filename)
 
 
 
21
 
22
  def delete_input_files(input_dir):
23
  wav_dir = Path(input_dir) / "wav"
 
30
  return None, "No file uploaded"
31
 
32
  filename = os.path.basename(file.name)
33
+
34
+ match = re.match(r'^(.*? - .*?)(?: \[.*\]|\(.*\))?$', filename)
35
+ formatted_title = match.group(1) if match else filename
36
+
37
+ formatted_title = sanitize_filename(formatted_title.strip())
38
 
39
  input_path = os.path.join(INPUT_FOLDER, "wav", f"{formatted_title}.wav")
40
  os.makedirs(os.path.dirname(input_path), exist_ok=True)