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
- Install dependencies:
-
Set up a Spotify dev account with appropriate keys:
- Follow Creating a Spotify Account
- Save keys in the
.envfile
-
Generate YouTube Music OAuth credentials:
- Follow the ytmusicapi setup guide
- Save
ytm_oauth.jsonusinguv run ytmusicapi oauth --file ytm_oauth.json
-
Set up environment variables in a
.envfile:
# 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:
- Export your YouTube Music liked songs and playlists
- Find matching tracks on Spotify using fuzzy matching
- Create playlists on Spotify (if they don't exist)
- Generate and upload cover images for playlists without covers
- 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 IDsyt_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
- Fork the repository
- Create a feature branch
- Make your changes
- Run
ruff checkandruff format - Submit a pull request
License
MIT License