Skip to content

Commit

Permalink
Merge branch 'fix/special-chars-in-final-path-name'
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30 committed Apr 14, 2024
2 parents a0e1650 + 498061e commit cd8279f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
exec(open("ytmdl/__version__.py").read())

req_pkgs = [
'yt-dlp>=2022.7.6',
'yt-dlp>=2024.4.9',
'mutagen',
'itunespy',
'requests',
Expand Down
3 changes: 1 addition & 2 deletions ytmdl/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def __replace_special_characters(passed_name: str) -> str:
/ with a `-` so that it does not raise any errors
related to the OS while moving the file
"""
# TODO: Also add support for removing backslash
return sub(r'/', '-', passed_name)
return sub(r'[\\/|&?;:#~!"<>$%^*{}[\]+=`´]+', '-', passed_name)


def get_abs_path(path_passed: str) -> str:
Expand Down
14 changes: 10 additions & 4 deletions ytmdl/song.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ def getChoice(SONG_INFO, type):
return choice - 1 if (choice != -1 and choice != -2) else choice


def get_song_name_to_save(name: str, format: str) -> str:
"""
Get the song name to save the song with.
"""
return f"{__replace_special_characters(name)}.{format}"


def set_MP3_data(song, song_path):
"""
Set the meta data if the passed data is mp3.
Expand Down Expand Up @@ -228,8 +235,7 @@ def set_MP3_data(song, song_path):

data.save()

defaults.DEFAULT.SONG_NAME_TO_SAVE = __replace_special_characters(
song.track_name) + '.mp3'
defaults.DEFAULT.SONG_NAME_TO_SAVE = get_song_name_to_save(song.track_name, "mp3")

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

audio.save()

defaults.DEFAULT.SONG_NAME_TO_SAVE = song.track_name + '.m4a'
defaults.DEFAULT.SONG_NAME_TO_SAVE = get_song_name_to_save(song.track_name, "m4a")

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

mutagen_file.save()

defaults.DEFAULT.SONG_NAME_TO_SAVE = song.track_name + '.opus'
defaults.DEFAULT.SONG_NAME_TO_SAVE = get_song_name_to_save(song.track_name, "opus")

# Rename the downloaded file
os.rename(SONG_PATH, os.path.join(
Expand Down

0 comments on commit cd8279f

Please sign in to comment.