This project automates the process of transferring your liked songs from Spotify to a YouTube playlist. It leverages the Spotify API to fetch your liked music and the YouTube Data API to search for the corresponding songs and add them to a designated playlist on your YouTube account.
- Spotify Integration: Fetches your liked songs from your Spotify account.
- YouTube Integration: Searches for songs on YouTube and adds them to a specified playlist.
- Caching: Supports caching of Spotify data to avoid repeated API calls.
- Rate Limiting: Includes a mechanism to handle the YouTube Data API's quota limits by pausing the script for 24 hours after adding 200 songs.
- Duplicate Handling: Removes duplicate tracks from the Spotify liked list before adding to youtube.
- Error Handling: Basic error handling for YouTube API interactions.
- Python 3.x: Ensure you have Python 3 installed on your system.
- Spotify Account: You need an active Spotify account.
- YouTube Account: You need an active YouTube account.
- API Keys:
- Spotify API: You need to create a Spotify application to get the required credentials. See the "Setup" section for details.
- YouTube Data API: You need to create a project on the Google Cloud Console to get the necessary API credentials. See the "Setup" section for details.
-
Clone the repository:
git clone <your-repository-url> cd Spotify2YTMusic
-
Install Dependencies:
pip install -r requirements.txt
The requirements.txt file should be updated to add all necessary libraries. A suggestion is at the bottom of this file
-
Spotify API:
- Go to the Spotify Developer Dashboard.
- Create a new application.
- Once created, you'll find your
Client IDandClient Secret. - Add
http://localhost:8080in the Redirect URIs - Create a
.envfile in the project root directory and add the following lines, replacingYOUR_SPOTIFY_CLIENT_IDandYOUR_SPOTIFY_CLIENT_SECRETwith your actual credentials:
SPOTIPY_CLIENT_ID=YOUR_SPOTIFY_CLIENT_ID SPOTIPY_CLIENT_SECRET=YOUR_SPOTIFY_CLIENT_SECRET SPOTIPY_REDIRECT_URI=http://localhost:8080 -
YouTube Data API:
- Go to the Google Cloud Console.
- Create a new project.
- Enable the YouTube Data API v3 for your project.
- Create credentials for the project, choosing
OAuth client IDandWeb applicationas the application type. - Download the
client_secret_desktop.jsonfile and place it in the project's root directory. - In the
.envfile, add the following line, replacingYOUR_YOUTUBE_API_KEYwith your API key: - Authorized following redirect URIs
YT_API_KEY=YOUR_YOUTUBE_API_KEY -
Run the App:
python main.py
- The first time you run the app, a browser window will open, asking you to authenticate with Spotify and Youtube.
- The app will use a local server to authenticate, once it does, it will close. The app will continue working in the terminal.
-
Initial Run:
- The first time you run the script, it will fetch your liked songs from Spotify and store them in
liked_music.csv. - It will also authenticate with YouTube and create a new playlist called "Spot2Yt" or use the one with that name if it exists.
- Then, it will proceed to search each song on YouTube and add it to the "Spot2Yt" playlist.
- The first time you run the script, it will fetch your liked songs from Spotify and store them in
-
Subsequent Runs:
- On subsequent runs, if you don't make any changes, by default, it will use the cached data in
liked_music.csvfor speed. - If you want to refresh the cache, you will have to change
SP_DF = spotify_call(True)inmain()function toSP_DF = spotify_call(False)before running the script again. - It will pick up where it left off, adding new songs to the playlist.
- On subsequent runs, if you don't make any changes, by default, it will use the cached data in
Spotify2YTMusic/
├── main.py # Main script for the song transfer process
├── spotify.py # Handles Spotify API interactions
├── youtube_search.py # Handles YouTube Data API interactions
├── client_secret_desktop.json # Your YouTube API credentials (download from Google Cloud)
├── liked_music.csv # Cached Spotify data (created after the first run)
├── requirements.txt # Project dependencies list
├── .env # Environment variables (API keys)
└── README.md # This file (project documentation)
-
main.py: The main script that orchestrates the transfer process.spotify_call(): Fetches liked songs from Spotify (with caching).youtube_playlist_id(): Gets the YouTube playlist.youtube_call(): Searches and adds songs to the YouTube playlist.main(): Entry point for the script.
-
spotify.py: Contains theSpotifyclass, which handles the authentication and interaction with the Spotify API. -
youtube_search.py: Contains theYoutubeclass, which handles the authentication and interaction with the YouTube Data API.
- The YouTube Data API has a quota limit for actions like adding songs to playlists. - 10000 units daily
- This script adds a song to the playlist(costs 50 units each), and then checks if it has added 200 songs(daily limit), if so, it will make the script sleep for 24 hours, before attempting to add more songs. This is a way to bypass the quota.