From 8485a30388064ea3862c82107f51de34cbd474b3 Mon Sep 17 00:00:00 2001 From: John Goodliff Date: Fri, 13 Sep 2024 17:22:27 -0600 Subject: [PATCH] Print available playlist names and fail immediately when the target playlist cannot be found --- playlist-archiver-for-spotify.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/playlist-archiver-for-spotify.py b/playlist-archiver-for-spotify.py index 518d0db..494b7a4 100644 --- a/playlist-archiver-for-spotify.py +++ b/playlist-archiver-for-spotify.py @@ -68,6 +68,7 @@ def get_playlist_id(sp, playlist_name): chunk_size = 50 chunk_offset = 0 playlist_id = None + playlist_names = [] while not playlist_id: chunked_playlists = sp.current_user_playlists(limit=chunk_size, offset=chunk_offset)['items'] @@ -80,11 +81,16 @@ def get_playlist_id(sp, playlist_name): if playlist['name'] == playlist_name: playlist_id = playlist['id'] debug(f'Playlist id of {playlist_name} is {playlist_id}') + break + else: + playlist_names.append(playlist['name']) chunk_offset += chunk_size if not playlist_id: - warn(f'Playlist {playlist_name} not found. Is the playlist name correct?') + playlist_names.sort() + formatted_playlist_names = '\n '.join(playlist_names) + raise ValueError(f'Playlist "{playlist_name}" not found. Is the playlist name correct? Available playlists:\n {formatted_playlist_names}') return playlist_id