90% of this generated by GitHub Copilot, even README ๐คก
This project is a Spotify playlist generator that uses the Spotify API and Claude GPT to create personalized playlists based on your liked songs and mood. The application fetches your liked songs, sends them to Claude GPT for analysis, and generates playlists with song recommendations tailored to your music taste and current mood.
- Fetches your liked songs from Spotify
- Analyzes your music taste using Claude GPT
- Generates personalized playlists based on your mood (happy, calm, energetic, working)
- Automatically updates playlists every 10 hours
- Web interface for easy authentication and playlist generation
- Current price for Claude GPT around $0.20 for one playlist
-
Clone the repository:
git clone https://github.com/your-username/spotify-playlist-generator.git
-
Install the required dependencies:
pip install spotipy flask apscheduler Flask-Session
-
Set up your Spotify app credentials:
- Create a new app on the Spotify Developer Dashboard
- Set the
SPOTIPY_CLIENT_ID
andSPOTIPY_CLIENT_SECRET
variables in the code with your app's client ID and client secret - Set the
SPOTIPY_REDIRECT_URI
variable tohttp://127.0.0.1:5003/callback
for local development - Don`t forget to add callback url to you Spotify app
- Until you Spotify app is in development mode, you can only use your own account to authenticate, if you need to add users manually using User Management tab in your Spotify app setting
-
Set up your Claude GPT API key:
- Sign up for an API key at Anthropic
- Set the
CLUDE_API_KEY
variable in the code with your API key
-
Run the application:
python spotify.py
-
Open your web browser and navigate to
http://127.0.0.1:5003
-
Click on the "Login with Spotify" button to authenticate with your Spotify account
-
Once authenticated, the application will fetch your liked songs, analyze your music taste, and generate personalized playlists based on your mood
-
The playlists will be automatically updated and regenerated everyday at 10:00 server time
fetch_liked_tracks(sp, limit)
: Fetches your liked songs from Spotify up to the specified limitclear_playlist(sp, playlist_id)
: Clears the specified playlistcreate_playlist_if_not_exists(sp, user_id, playlist_name)
: Creates a new playlist with the specified name if it doesn't existadd_tracks_to_playlist(sp, playlist_id, recomendation)
: Adds tracks to the specified playlist based on the AI recommendationsget_ai_recomendations(liked_tracks, mood)
: Sends your liked songs and mood to Claude GPT and retrieves song recommendationsdo_job(user_id, user_token)
: Performs the playlist generation job for a specific userwrite_to_db(user_id, user_token)
: Writes user information to the SQLite databasecheck_updates_job()
: Checks for users who haven't updated their playlists in the last 10 hours and triggers the playlist generation job
spotipy
: A Python library for the Spotify Web APIanthropic
: A Python library for the Claude GPT APIflask
: A lightweight web framework for Pythonapscheduler
: A Python library for scheduling jobssqlite3
: A Python library for working with SQLite databases
- Original promt can be found in
get_ai_recomendations(liked_tracks, mood)
- You can change mood preset by changing mood variable in
get_ai_recomendations(liked_tracks, mood)
calls insidedo_job(user_id, user_token)
method - For example, change
recomendation_happy = get_ai_recomendations(tracks, "happy")
torecomendation_happy = get_ai_recomendations(tracks, "sad")
and it will generate playlist for sad mood
This project is licensed under the MIT License.