Skip to content

Commit cd8279f

Browse files
committed
Merge branch 'fix/special-chars-in-final-path-name'
2 parents a0e1650 + 498061e commit cd8279f

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
exec(open("ytmdl/__version__.py").read())
1212

1313
req_pkgs = [
14-
'yt-dlp>=2022.7.6',
14+
'yt-dlp>=2024.4.9',
1515
'mutagen',
1616
'itunespy',
1717
'requests',

ytmdl/dir.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def __replace_special_characters(passed_name: str) -> str:
1818
/ with a `-` so that it does not raise any errors
1919
related to the OS while moving the file
2020
"""
21-
# TODO: Also add support for removing backslash
22-
return sub(r'/', '-', passed_name)
21+
return sub(r'[\\/|&?;:#~!"<>$%^*{}[\]+=`´]+', '-', passed_name)
2322

2423

2524
def get_abs_path(path_passed: str) -> str:

ytmdl/song.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ def getChoice(SONG_INFO, type):
187187
return choice - 1 if (choice != -1 and choice != -2) else choice
188188

189189

190+
def get_song_name_to_save(name: str, format: str) -> str:
191+
"""
192+
Get the song name to save the song with.
193+
"""
194+
return f"{__replace_special_characters(name)}.{format}"
195+
196+
190197
def set_MP3_data(song, song_path):
191198
"""
192199
Set the meta data if the passed data is mp3.
@@ -228,8 +235,7 @@ def set_MP3_data(song, song_path):
228235

229236
data.save()
230237

231-
defaults.DEFAULT.SONG_NAME_TO_SAVE = __replace_special_characters(
232-
song.track_name) + '.mp3'
238+
defaults.DEFAULT.SONG_NAME_TO_SAVE = get_song_name_to_save(song.track_name, "mp3")
233239

234240
# Rename the downloaded file
235241
to_save_as = os.path.join(
@@ -296,7 +302,7 @@ def set_M4A_data(song, song_path):
296302

297303
audio.save()
298304

299-
defaults.DEFAULT.SONG_NAME_TO_SAVE = song.track_name + '.m4a'
305+
defaults.DEFAULT.SONG_NAME_TO_SAVE = get_song_name_to_save(song.track_name, "m4a")
300306

301307
# Rename the downloaded file
302308
os.rename(SONG_PATH, os.path.join(
@@ -361,7 +367,7 @@ def set_OPUS_data(song, song_path):
361367

362368
mutagen_file.save()
363369

364-
defaults.DEFAULT.SONG_NAME_TO_SAVE = song.track_name + '.opus'
370+
defaults.DEFAULT.SONG_NAME_TO_SAVE = get_song_name_to_save(song.track_name, "opus")
365371

366372
# Rename the downloaded file
367373
os.rename(SONG_PATH, os.path.join(

0 commit comments

Comments
 (0)