File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919
2020# Spotify authentication
2121sp = spotipy .Spotify (auth_manager = SpotifyOAuth (client_id = client_id ,
22- client_secret = client_secret ,
23- redirect_uri = redirect_uri ,
24- scope = "playlist-read-private playlist-read-collaborative user-library-read" ))
22+ client_secret = client_secret ,
23+ redirect_uri = redirect_uri ,
24+ scope = "playlist-read-private playlist-read-collaborative user-library-read" ))
2525
2626def rate_limited_request (func , * args , ** kwargs ):
2727 """Handles rate limiting by retrying after the specified delay."""
@@ -45,7 +45,9 @@ def export_playlist_to_csv(playlist, output_dir):
4545 print (playlist ['name' ])
4646
4747 # Construct the file path
48- playlist_filename = playlist ['name' ].replace (' ' , '_' ).lower () + ".csv"
48+ # Sanitize the playlist name to create a safe filename
49+ sanitized_name = "" .join (c if c .isalnum () or c in (' ' , '_' , '-' ) else '_' for c in playlist ['name' ])
50+ playlist_filename = sanitized_name .replace (' ' , '_' ).lower () + ".csv"
4951 file_path = os .path .join (output_dir , playlist_filename )
5052
5153 with open (file_path , mode = 'w' , newline = '' , encoding = 'utf-8' ) as file :
You can’t perform that action at this time.
0 commit comments