mirror of
https://github.com/Matewoo/spotify-lyric-downloader.git
synced 2026-11-18 13:52:50 +01:00
add function to sanitize folder names
this function removes special characters from album name for folder creation
This commit is contained in:
+9
-4
@@ -22,6 +22,8 @@ scope = "user-read-currently-playing"
|
|||||||
sp = spotipy.Spotify(auth_manager = SpotifyOAuth(scope = scope))
|
sp = spotipy.Spotify(auth_manager = SpotifyOAuth(scope = scope))
|
||||||
current_track = sp.current_user_playing_track()
|
current_track = sp.current_user_playing_track()
|
||||||
|
|
||||||
|
def sanitize_folder_name(name):
|
||||||
|
return re.sub(r'[<>:"/\\|?*]', '_', name)
|
||||||
|
|
||||||
def replace_line(database, line_num, text):
|
def replace_line(database, line_num, text):
|
||||||
lines = open(database, 'r').readlines()
|
lines = open(database, 'r').readlines()
|
||||||
@@ -133,13 +135,16 @@ else:
|
|||||||
os.chdir(artist)
|
os.chdir(artist)
|
||||||
artistdir = os.getcwd()
|
artistdir = os.getcwd()
|
||||||
|
|
||||||
|
#remove special characters from album name for folder creation
|
||||||
|
sanitized_album_name = sanitize_folder_name(album)
|
||||||
|
|
||||||
#creates album folder
|
#creates album folder
|
||||||
if os.path.isdir(album):
|
if os.path.isdir(sanitized_album_name):
|
||||||
os.chdir(album)
|
os.chdir(sanitized_album_name)
|
||||||
albumdir = os.getcwd()
|
albumdir = os.getcwd()
|
||||||
else:
|
else:
|
||||||
os.mkdir(album)
|
os.mkdir(sanitized_album_name)
|
||||||
os.chdir(album)
|
os.chdir(sanitized_album_name)
|
||||||
albumdir = os.getcwd()
|
albumdir = os.getcwd()
|
||||||
|
|
||||||
os.chdir(host_dir)
|
os.chdir(host_dir)
|
||||||
|
|||||||
Reference in New Issue
Block a user