Skip to content

dcl09/spotify_to_youtube_music_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spotify to YouTube Music Playlist Converter

This project allows automated transfer of playlists from Spotify to YouTube Music. It uses OAuth 2.0 authentication to access the official APIs of Spotify and YouTube, searching for tracks and creating corresponding playlists in your YouTube Music account.


Prerequisites

  • Python 3.8 or higher
  • A Spotify Developer Account
  • A Google Cloud Project with YouTube Data API v3 enabled
  • Pip (included with Python)

Installation

After obtaining the source code, install the dependencies:

pip install -r requirements.txt

Credentials Setup

The application requires OAuth 2.0 authentication for both Spotify and YouTube.

Spotify

  1. Go to the Spotify Developer Dashboard.
  2. Create a new application and copy the Client ID and Client Secret.
  3. On the first execution, the script will request these credentials.
  4. A browser window will open for login. A token is saved locally (.cache) for subsequent executions.

YouTube

  1. Go to the Google Cloud Console.
  2. Enable the YouTube Data API v3.
  3. Create OAuth credentials (type: OAuth 2.0 Client ID) and download the client_secret.json file.
  4. Place client_secret.json in the project root.
  5. On first execution, a browser window will open for login. A token.json file is created and reused automatically.

Important: Do not commit client_secret.json, spotify_credentials.json, or token.json to version control. These files are included in .gitignore.


Usage

Run the main script:

python spotify_to_ytmusic_transfer.py

Steps:

  1. Provide the Spotify playlist URL.
  2. Choose to create a new YouTube Music playlist or add tracks to an existing one.
  3. The program searches for each track on YouTube Music and transfers it.
  4. If the YouTube API quota is exceeded, remaining tracks are saved in a text file for later transfer.

Technical Details

  • Spotify: Authentication via Spotipy. OAuth 2.0 flow opens a browser on first use; tokens are cached locally.
  • YouTube: Authentication via Google OAuth 2.0. token.json stores refresh tokens to renew access automatically.
  • Track Matching: Tracks are matched by title and artist because Spotify and YouTube Music do not share track IDs.
  • API Limits: The YouTube API has daily quotas. Transfers are batched, and unmatched tracks are saved to avoid loss.

Dependencies

Installed automatically via requirements.txt:

  • spotipy — Spotify API client
  • google-auth, google-auth-oauthlib — OAuth 2.0 authentication
  • google-api-python-client — YouTube Data API access
  • tqdm — Progress bar

Project Structure and File Safety

  • .gitignore is configured to ignore sensitive credentials:

    client_secret.json
    spotify_credentials.json
    token.json
    
  • Python cache and environment directories are ignored to keep the repository clean.


Architecture Overview

  1. Authenticate Spotify and YouTube accounts using OAuth 2.0.
  2. Fetch Spotify playlist tracks using Spotipy with paginated requests.
  3. For each track, search YouTube Music and obtain the corresponding video ID.
  4. Create or update the YouTube Music playlist with matched tracks, batching requests to respect API limits.
  5. Save any unmatched tracks for manual handling or subsequent retries.

License

This project is licensed under Creative Commons Attribution-NoDerivatives 4.0.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages