Harness the power of GPT to generate personalized Spotify playlists with a simple text prompt. Curate your musical experience effortlessly! This TypeScript project provides an easy-to-use command line tool that generates a playlist on Spotify based on a user's prompt. Powered by OpenAI's GPT.
- 🎵 Generates a playlist based on user prompts
- 🧠 Utilizes OpenAI's GPT for AI-powered playlist creation
- 🔍 Supports different search methods for finding songs on Spotify
- 📝 Automatically creates a title and description for the generated playlist
- 🚀 Supports dry-run mode for testing without creating a playlist on Spotify
- 🐛 Verbose logs for debugging
- Node.js (>= 14.x)
- npm (>= 6.x)
- OpenAI API key
- Spotify Developer account
In order to generate a playlist on your account, the following tokens are needed:
OPENAI_TOKEN
SPOTIFY_CLIENT_ID
SPOTIFY_CLIENT_SECRET
Please obtain these tokens and insert them into a .env
file in the project root, using the following format:
OPENAI_TOKEN=your_openai_token
SPOTIFY_CLIENT_ID=your_spotify_client_id
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
Don't forget to replace your_openai_token
, your_spotify_client_id
, and your_spotify_client_secret
with your actual token values.
- Go to OpenAI and create an account or log in.
- Navigate to the API keys page.
- Click the "Create new secret key" button and copy the key generated.
- Visit the Spotify Developer Dashboard and log in with your Spotify account or create a new one.
- Click on the "Create App" button.
- Set the redirect url to
http://localhost:<redirect_port>}/callback
where "<redirect_port>" is the same as specified ingenerator.config.json
- Fill in the required information for your new app and click "Save".
- You will be redirected to your app's overview page. Here, you can find your
SPOTIFY_CLIENT_ID
(Client ID) andSPOTIFY_CLIENT_SECRET
(Client Secret).
To begin using the generator you will need to create a generator.config.json
file in the project root. This file allows you to set your Spotify username, choose the GPT model, and specify a redirect port for authentication.
Here's an example generator.config.json
file:
{ "spotify_username": "your_spotify_username", "gpt_model": "gpt_model_name", "redirect_port": your_redirect_port }
spotify_username
(string): Set your Spotify username (required for playlist generation).gpt_model
(string): Choose the GPT model you want to use (e.g., "gpt-3", "gpt-3.5-turbo", "gpt-4").redirect_port
(integer): Specify the port for the OAuth2 redirect during Spotify authentication. Ensure this matches the redirect URL specified in your Spotify Developer Dashboard.
Replace your_spotify_username
, gpt_model_name
, and your_redirect_port
with your actual values.
Run: npm run playlist <Your Prompt>
with the following optional flags
Option | Description | Type | Default |
---|---|---|---|
`-t, --temperature` | Adjusts output randomness for diverse, creative responses | number [0-1] | 850 |
`-mt, --maxTokens` | Maximum amount of tokens for the response | number [integer] | 0.5 |
`-dg, --debugGpt` | Display verbose GPT related logging for debugging | boolean | false |
`-ds, --debugSpotify` | Display verbose Spotify related logging for debugging | boolean | false |
`--dryRun` | Query GPT without creating a playlist | boolean | false |
`-st, --searchType` | Method used to search for songs on Spotify | 'safe' |
search for ${artist} ${songName}
and return the first result
Attempt to match a song on Spotify by trying various combinations of the song and artist names, ensuring that it can find a match even if the initial query doesn't yield the desired result.
Define an array of three different search queries:
${song} ${artist}
: Combines the song and artist names.${artist} ${song}
: Reverses the order of song and artist names.${artist}
: Uses only the artist name.
For each query in the array, Check if there's a match between the expected artist and any of the actual artists on the track. If so return the track. If no match is found, ignore the track.
* Please note that the speed and quality of the generated playlist varies between different models of GPT.
For the best results it is recommended to use gpt-4 if possible.
Prompt | Model | Temperature |
---|---|---|
Japanese city pop songs that are easy for begginers | gpt-4 | 0.5 |
25 Songs by the big 4 of thrash metal | gpt-4 | 0.5 |
An ecclectic mix of Death Grips and Kero Kero Bontio | gpt-4 | 0.5 |
Songs about funny dogs and sad presidents | gpt-4 | 0.5 |
If you encounter any issues or errors, try the following steps:
- Make sure you have the correct tokens and credentials set up in your `.env` file.
- Use the `--debugGpt` and `--debugSpotify` options to see verbose logs for better understanding of the issue.
- Make sure your Node.js and npm versions meet the minimum requirements mentioned in the Prerequisites section.