This script allows you to export your Spotify playlists as CSV files, including the track name, artist, album, and URL.
-
Clone or download this repository to your local machine.
-
(Optional) Make virtual environment
-
Install the required dependencies by running the following command:
pip install -r requirements.txt -
Obtain Spotify API credentials:
-
Create a Spotify Developer account at https://developer.spotify.com/.
-
Create a new Spotify application to get the Client ID and Client Secret.
-
Set the Redirect URI to a valid URI (e.g., https://developer.spotify.com/).
-
Note down the Client ID, Client Secret, and Redirect URI.
-
-
Create a
.envfile in the project directory with your Spotify API credentials:
CLIENT_ID=your_client_id_here
CLIENT_SECRET=your_client_secret_here
REDIRECT_URI=your_redirect_uri_here
USER_ID=your_spotify_username_here
-
Run the script with the
--authorizeflag:python main.py --authorize -
The script will automatically open your browser to the Spotify authorization page.
-
After authorizing the application, you will be redirected to the specified Redirect URI. Copy the authorization code from the URL (the part after
?code=). -
Paste the authorization code into the script's prompt.
-
The script will save your tokens for future use and export your playlists.
Once authorized, you can run the script in headless mode:
- Interactive mode:
python main.py(will prompt for authorization if tokens are expired) - Headless mode:
python main.py --headless(will exit if tokens are expired, requiring manual re-authorization)
The script will fetch your playlists and save each playlist as a separate CSV file in the backup folder. The CSV files will contain the track name, artist, album, and URL for each song in the playlist.
--authorize: Force authorization flow (required for first run)--headless: Run in headless mode (no interactive prompts)