Skip to content

TANEJS4/Spotify2YTMusic

Repository files navigation

Spotify2YTMusic

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.

Features

  • 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.

Prerequisites

  1. Python 3.x: Ensure you have Python 3 installed on your system.
  2. Spotify Account: You need an active Spotify account.
  3. YouTube Account: You need an active YouTube account.
  4. 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.

Installation

  1. Clone the repository:

    git clone <your-repository-url>
    cd Spotify2YTMusic
  2. 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

Setup

  1. Spotify API:

    • Go to the Spotify Developer Dashboard.
    • Create a new application.
    • Once created, you'll find your Client ID and Client Secret.
    • Add http://localhost:8080 in the Redirect URIs
    • Create a .env file in the project root directory and add the following lines, replacing YOUR_SPOTIFY_CLIENT_ID and YOUR_SPOTIFY_CLIENT_SECRET with your actual credentials:
    SPOTIPY_CLIENT_ID=YOUR_SPOTIFY_CLIENT_ID
    SPOTIPY_CLIENT_SECRET=YOUR_SPOTIFY_CLIENT_SECRET
    SPOTIPY_REDIRECT_URI=http://localhost:8080
    
  2. YouTube Data API:

    YT_API_KEY=YOUR_YOUTUBE_API_KEY
    
  3. 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.

Usage

  1. 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.
  2. Subsequent Runs:

    • On subsequent runs, if you don't make any changes, by default, it will use the cached data in liked_music.csv for speed.
    • If you want to refresh the cache, you will have to change SP_DF = spotify_call(True) in main() function to SP_DF = spotify_call(False) before running the script again.
    • It will pick up where it left off, adding new songs to the playlist.

File Structure

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)

Code Explanation

  • 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 the Spotify class, which handles the authentication and interaction with the Spotify API.

  • youtube_search.py: Contains the Youtube class, which handles the authentication and interaction with the YouTube Data API.

Rate Limiting and Quota

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages