This is a Python script that manages Spotify playlists by creating new playlists and updating existing ones. It utilizes the Spotify Web API, Spotipy library, and web scraping to retrieve playlist details from Apple Music.
Before running the script, make sure you have the following:
- Python 3.x installed
- Required Python packages installed (see
requirements.txt
) - Spotify API credentials (client ID and client secret)
Check the Spotipy's full documentation is online at Spotipy Documentation
or the Spotipy GitHub Repo the tutorial.md to get started. - Environment variables set in a
.env
file (see.env.example
for required variables)
- Clone this repository:
git clone https://github.com/MichaelOgunjimi/AppleToSpotifyPlaylistSync.git
cd spotify-playlist-manager
- Install the required packages using pip:
pip install -r requirements.txt
- Set up your environment variables by creating a
.env
file based on the.env.example
file or edit the below with your credentials and run.
ni ".env"
echo "CLIENT_ID=YOUR-SPOTIFY-CLIENT-ID" >> .env
echo "CLIENT_SECRET=YOUR-SPOTIFY-CLIENT-SECRET" >> .env
-
Open the
main.py
file and modify theplaylist_manager
and theplaylist
to include your desired playlists. Each playlist should have the following properties:-
playlist_url
: The URL of the playlist on Apple Music. -
artist_name
: The name of the artist associated with the playlist. -
playlist_name
: The desired name for the playlist on Spotify. -
playlist_description
: The desired description for the playlist on Spotify. -
image_path
: The URL or local path of the playlist cover image .- You can exclude this if you do not want to add image to your playlist.
-
In the
main.py
you can uncomment the last if statement or modify if you want to automate the program to update on a particular day:- Preview of the statement look like this:
if get_current_day_of_week() == "Monday": for playlist in essential_playlist: playlist_manager.update_tracks_in_playlist(playlist=playlist)
-
-
Run the script:
python main.py
The script will perform the following actions:
- Instantiate the
SpotifyPlaylistManager
class and authenticate with the Spotify API. - Create Spotify playlists based on the
New_Playlist
make sure you have modified this to with the correct variables- See the example folder for the exampele of the action you want to run
- Add tracks to the created playlists by searching for them on Spotify using the Apple Music playlist details.
- Update the existing playlists on Mondays by replacing the tracks with the latest ones from Apple Music.
- If you want to customize the behavior of the script, you can modify the following files:
SpotifyPlaylistManager.py
: Contains theSpotifyPlaylistManager
class, which handles interactions with the Spotify API.Playlist.py
: Contains thePlaylist
class, which represents a playlist and handles web scraping of Apple Music playlist details.utils.py
: Contains utility functions used by the main script.
Feel free to explore and customize the code according to your needs!
Contributions are welcome! Here are a few guidelines to get started:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your modifications and ensure they adhere to the coding style.
- Write tests to validate your changes (if applicable).
- Commit your changes and push them to your fork.
- Submit a pull request detailing your changes and their benefits.
Please ensure that you follow the Code of Conduct when contributing to this project.
This project is licensed under the MIT License