This script logs the current song playing on your Spotify account to a text file called current_song.txt. It continuously checks for song changes and updates the text file accordingly.
- Python 3.6 or higher
spotipy
librarypython-dotenv
library
- Clone this repository or download the files.
- Install the required Python libraries:
pip install spotipy python-dotenv
- Create a Spotify Developer account and register a new application to get your API credentials (Client ID, Client Secret, and Redirect URI).
- Create a .env file in the same directory as your Python script and add your API credentials:
SPOTIPY_CLIENT_ID=your_client_id
SPOTIPY_CLIENT_SECRET=your_client_secret
SPOTIPY_REDIRECT_URI=your_redirect_uri
SLEEP_DELAY=10
- Replace your_client_id, your_client_secret, and your_redirect_uri with your actual API credentials.
- Go to the Spotify Developer Dashboard: https://developer.spotify.com/dashboard/applications
- Log in with your Spotify account or sign up for a new account if you don't have one.
- Click on the "Create an App" button.
- Fill in the required information for your new app (name, description, etc.) and click "Create" at the bottom of the form.
- Once your app is created, you'll be redirected to the app's dashboard, where you'll find your
Client ID
andClient Secret
. Copy these values. - Click on the "Edit Settings" button in the app's dashboard.
- In the "Redirect URIs" field, enter a valid redirect URI for your application. For local development, you can use http://localhost:8888/callback/. Make sure to include the trailing slash. Click "Add" and then click "Save" at the bottom of the form.
- Copy the Redirect URI you just added.
Now you have your Spotify API credentials: Client ID, Client Secret, and Redirect URI. Add these values to your .env
file as described above.
Run the script by executing the following command:
python script.py
The script will create or update a file named current_song.txt
in the same directory, containing the currently playing song and artist on your Spotify account.
To stop the script, press Ctrl+C in the terminal.
To run the tests, execute the following command:
python test_script.py
This will run the test cases and report the results.