Created
June 29, 2025 10:48
-
-
Save itspacchu/2c9385fc24e8a1e9da7a32e5da24a414 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is partially generated by Gemini! | |
import spotipy | |
from spotipy.oauth2 import SpotifyOAuth | |
import os | |
scope = "user-library-read" | |
try: | |
sp = spotipy.Spotify(auth_manager=SpotifyOAuth( | |
client_id=os.environ.get('SPOTIPY_CLIENT_ID'), | |
client_secret=os.environ.get('SPOTIPY_CLIENT_SECRET'), | |
redirect_uri=os.environ.get('SPOTIPY_REDIRECT_URI'), | |
scope=scope | |
)) | |
except spotipy.oauth2.SpotifyOauthError as e: | |
print("Authentication failed. Please check your credentials and redirect URI.") | |
print(f"Error: {e}") | |
exit() | |
liked_songs = [] | |
offset = 0 | |
limit = 50 # The maximum number of items to return in a single request. | |
results = sp.current_user_saved_tracks(limit=limit, offset=offset) | |
while results['items']: | |
for item in results['items']: | |
track = item['track'] | |
track_name = track['name'] | |
artist_names = ', '.join([artist['name'] for artist in track['artists']]) | |
liked_songs.append(f"{track_name} - {artist_names}") | |
offset += limit | |
results = sp.current_user_saved_tracks(limit=limit, offset=offset) | |
output_filename = "liked_songs.txt" | |
with open(output_filename, 'w', encoding='utf-8') as f: | |
for song in liked_songs: | |
f.write(song + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment