Skip to content

Commit 6a2564d

Browse files
committed
sanitized playlist filename
1 parent de8f321 commit 6a2564d

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

exportify.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
# Spotify authentication
2121
sp = 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

2626
def 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:

0 commit comments

Comments
 (0)