GitHub - akshetpandey/ytm2spotify: Python tool to migrate from YouTube Music to Spotify

2 min read Original article ↗

YTM2Spotify

A Python tool to migrate your YouTube Music playlists and liked songs to Spotify, with automatic cover image generation.

Features

  • Playlist Migration: Transfer all your YouTube Music playlists to Spotify
  • Liked Songs Migration: Migrate your liked songs from YouTube Music to Spotify
  • Smart Track Matching: Uses fuzzy matching to find the best Spotify equivalents
  • Automatic Cover Images: Generates cover images for playlists using OpenAI
  • Progress Tracking: Rich progress bars and detailed logging
  • Incremental Updates: Only processes new songs/playlists since last run
  • Caching: Saves track matches to avoid re-searching

Prerequisites

  • Python 3.13+
  • YouTube Music account
  • Spotify account
  • OpenAI API key (for cover image generation)

Setup

  1. Install dependencies:
  1. Set up a Spotify dev account with appropriate keys:

  2. Generate YouTube Music OAuth credentials:

  3. Set up environment variables in a .env file:

# Spotify API credentials
SPOTIPY_CLIENT_ID=your_spotify_client_id
SPOTIPY_CLIENT_SECRET=your_spotify_client_secret

# YouTube Music API credentials
YTM_CLIENT_ID=your_ytm_client_id
YTM_CLIENT_SECRET=your_ytm_client_secret

# OpenAI API key (for cover image generation)
OPENAPI_KEY=your_openai_api_key

Usage

Run the script using:

The tool will:

  1. Export your YouTube Music liked songs and playlists
  2. Find matching tracks on Spotify using fuzzy matching
  3. Create playlists on Spotify (if they don't exist)
  4. Generate and upload cover images for playlists without covers
  5. Add tracks to the appropriate playlists

Cover Image Generation

The tool automatically generates cover images for playlists using OpenAI's gpt-image-1 model If you don't have an OpenAI API key, the tool will skip cover image generation and continue with the migration.

Output Files

  • yt_liked_songs.json: Cached liked songs data with Spotify track IDs
  • yt_playlists.json: Cached playlist data with Spotify track IDs

These files are used for incremental updates and to avoid re-searching for track matches.

Error Handling

  • No Match Found: Tracks without Spotify matches are logged but don't stop the migration

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run ruff check and ruff format
  5. Submit a pull request

License

MIT License