This project provides a Python script that parses XML files containing music library information (such as those exported from iTunes) and creates corresponding playlists in Spotify, automatically populating them with available tracks found on Spotify.
Many thanks to Sam "Disco Inferno" Fearn for his timeless iTunes library for testing of this tool.
- Parses music library XML files.
- Creates Spotify playlists based on the XML file's contents.
- Searches Spotify for each track and adds it to the corresponding playlist.
- Skips creating playlists if they already exist in Spotify.
- Saves a summary of created playlists and tracks not found on Spotify.
Before you begin, ensure you have met the following requirements:
- Python 3.6+
- A Spotify account
- A Spotify Developer account with an application set up to obtain
client_id
,client_secret
, and aredirect_uri
. (See the official Spotify documentation here for information on how to do this).
- Clone this repository:
git clone https://github.com/yourusername/spotify-playlist-parser.git
- Navigate to the project directory:
cd spotify-playlist-parser
- Install the required Python packages:
pip install -r requirements.txt
- Rename .env.example to .env and fill in your Spotify application details:
SPOTIPY_CLIENT_ID=your_client_id
SPOTIPY_CLIENT_SECRET=your_client_secret
SPOTIPY_REDIRECT_URI=your_redirect_uri
USERNAME=your_spotify_username
- Make sure to add the redirect_uri to your Spotify application's whitelist in the Spotify Developer Dashboard.
Run the parser with:
python parser.py
spotify-playlist-parser/ │ ├── .env.example ├── .gitignore ├── README.md ├── requirements.txt │ ├── parser.py │ └── data/ └── example_music_library.xml
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
Distributed under the MIT License. See LICENSE for more information.
- To Sam "Disco Inferno" Fearn for his timeless iTunes library for testing of this tool.
- This project uses the Spotipy library for interacting with the Spotify Web API.
-
Environment Variables: For security and convenience, store your Spotify API credentials and username in environment variables. You could use a library like python-dotenv to load these from a .env file.
-
Running the Script: After setting up the environment variables, you can run parser.py to start the process. The script will prompt you for authentication with Spotify on the first run.
Ensure you remove or redact sensitive information like SPOTIPY_CLIENT_ID, SPOTIPY_CLIENT_SECRET, SPOTIPY_REDIRECT_URI, and USERNAME from your script before sharing or pushing to a public repository. Instead, load these from environment variables or a configuration file that is not tracked in your version control system.