https://youtu.be/-v0bw7eZYf0?feature=shared
The AI Playlist Generator is a Python-based application that automatically creates personalized Spotify playlists based on user input. By leveraging the Spotify API and ytmusicapi, this project generates dynamic playlists tailored to user preferences, such as mood, genre, or specific artists. The application provides a seamless way to curate music based on user-defined parameters.
- Automated Playlist Creation: Generates a new Spotify playlist based on user input.
- User Authentication: Securely connects to Spotify using OAuth.
- Song Selection: Fetches and adds relevant tracks based on the input criteria.
- Error Handling: Ensures proper API communication and catches common errors.
- Testing with Pytest: Includes unit tests to validate core functionalities.
- User Input: The user provides details such as mood, favorite artists, or genres.
- Spotify API Integration: The program authenticates the user and interacts with Spotify’s API.
- Playlist Generation: The script fetches recommended songs and creates a new playlist.
- Adding Tracks: The selected songs are added to the newly created playlist.
Ensure you have Python 3.12 installed.
-
Clone this repository:
git clone https://github.com/yourusername/playlist-generator cd playlist-generator -
Install dependencies:
pip install -r requirements.txt
-
Set up a Spotify Developer account and get your credentials:
- Visit Spotify Developer Dashboard
- Create an application and get your Client ID and Client Secret
- Set up a Redirect URI
-
Create a
.envfile and add your credentials:SPOTIPY_CLIENT_ID='your_client_id' SPOTIPY_CLIENT_SECRET='your_client_secret' SPOTIPY_REDIRECT_URI='your_redirect_uri'
Run the main script:
python project.pyFollow the on-screen instructions to generate your playlist.
├── project.py # Main script
├── test_project.py # Unit tests
├── requirements.txt # Dependencies
├── README.md # Project documentation
Run tests using pytest:
pytest test_project.py- Handling API rate limits
- Ensuring playlist name constraints are met
- Debugging authentication issues with Spotify API
- And for the biggest of all... I had to use ytmusicapi to get suggestions from YouTube Music and then pass them through Spotify's API to get song URLs and make it a playlist. This decision was made due to the realization that the
get_recommendationsendpoint of Spotify API has been deprecated! 🎧
- Improve recommendation logic with AI-based suggestions
- Add support for multiple streaming platforms
- Implement a web-based UI for better user experience
- Built as part of CS50P Final Project
- Uses Spotipy for Spotify API interaction
- Uses ytmusicapi for interaction with YouTube Music database
💡 A note from my end: I initially designed this project to allow users to input a query, which would be processed by Gemini to generate a set of parameters for Spotify's recommendation API. However, since Spotify's get_recommendations endpoint has been deprecated, I adapted the approach. Instead, the project now utilizes Gemini to generate search parameters, constructs a refined query, and retrieves song recommendations from the YouTube Music API. These songs are then searched on Spotify to obtain their URIs, which are used to create a curated playlist.
I hope you liked this project! - Deeptanshu Kumar 🎵