This Python script interacts with the Spotify API to manage playlists and fetch user information. It uses the Flask framework to run a local server and handle HTTP requests.
- Does it work with albums? No.
- Does it delete or replace older randomized playlists? No.
- How long does it take? Around 2 minutes at max.
- The script first reads the configuration values from the
config.yml
file, which includes the Spotify access token and playlist ID. - It then starts a Flask server on port 8888.
- When a user navigates to the server's URL in a web browser, the server responds with the
index.html
page. - The user can enter a playlist URL and choose whether to use the Liked Songs playlist.
- When the user clicks the "Log In" button, the server sends a POST request to the Spotify API to add tracks to the specified playlist.
- The server prints a success message if the tracks are added successfully, or an error message if there's a problem.
- The script uses the
requests
library's built-in JSON support to send the playlist data to the Spotify API, which simplifies the code and reduces the chance of errors. - It also uses Flask's built-in support for serving static files, which makes it easy to serve the
index.html
page.
- The script doesn't validate the playlist URL entered by the user, so it could crash if the URL is not a valid Spotify playlist URL.
- It also doesn't handle errors that could occur when reading the
config.yml
file, such as the file not existing or not being in the correct format. - The script does not delete old Randomized Playlists because for some reason the Spotify Web API did not give me updated playlists so I gave up.
To run the script, use the following command:
py main.py