A Python script that exports your Spotify playlists to YouTube Music, automatically matching and adding songs.
- Export any Spotify playlist (public or private) to YouTube Music
- Update existing YouTube Music playlists to match your Spotify playlists
- Automatic backup before updating (safety net if something goes wrong)
- Incremental updates: only adds new songs and removes deleted ones
- Automatic fallback to headless browser scraping if API access fails (works with playlists like "mint", "Top 50", etc.)
- Uses Playwright to render JavaScript and intercept network requests for reliable data extraction
- List all your Spotify playlists with the
--listcommand - Automatic song matching using track name and artist
- Progress tracking with detailed output
- Configurable playlist privacy settings
- Reports tracks that couldn't be found
- Email status notifications - Get notified when exports/updates start, complete, or encounter errors
- Python 3.7 or higher
- A Spotify account
- A YouTube/Google account with YouTube Music access
- Spotify Developer Application credentials
python3 -m pip install -r requirements.txtAfter installing Python packages, install Patchright browsers:
patchright install chromiumThis downloads the Chromium browser that Patchright uses for:
- Web scraping when the Spotify API doesn't work
- Automated YouTube Music authentication setup
- Go to the Spotify Developer Dashboard
- Log in with your Spotify account
- Click "Create an App"
- Fill in the app name and description
- Once created, you'll see your Client ID and Client Secret
- Click "Edit Settings" and add a Redirect URI:
http://localhost:8888/callback
Create a config.json file in the same directory as the script:
cp config.example.json config.jsonThen edit config.json with your credentials:
{
"spotify": {
"client_id": "your_spotify_client_id_here",
"client_secret": "your_spotify_client_secret_here",
"redirect_uri": "http://localhost:8888/callback"
},
"youtube_music": {
"headers_file": "headers_auth.json"
}
}Alternatively, you can use environment variables:
export SPOTIFY_CLIENT_ID="your_client_id_here"
export SPOTIFY_CLIENT_SECRET="your_client_secret_here"
export SPOTIFY_REDIRECT_URI="http://localhost:8888/callback"Or on Windows (PowerShell):
$env:SPOTIFY_CLIENT_ID="your_client_id_here"
$env:SPOTIFY_CLIENT_SECRET="your_client_secret_here"
$env:SPOTIFY_REDIRECT_URI="http://localhost:8888/callback"You have three options for YouTube Music authentication:
Simply run:
python3 spotify_to_youtube.py --setup-youtubeWhat happens:
- Opens a browser window to YouTube Music
- You log in to your Google/YouTube account
- Script automatically captures authentication headers
- Saves to
browser.jsonand verifies it works - Done! No manual copying/pasting required
This uses Patchright to avoid bot detection and automatically extract the required authentication headers.
ytmusicapi browserFollow the instructions to extract authentication headers from your browser:
- Open YouTube Music (music.youtube.com) in your browser and log in
- Open Developer Tools (F12)
- Go to the Network tab
- Find a request to
music.youtube.com - Copy the request headers as instructed
- Paste them when prompted
This will create a browser.json file automatically.
This method requires setting up a Google Cloud project and enabling the YouTube Data API v3:
- Go to Google Cloud Console
- Create a new project
- Enable "YouTube Data API v3"
- Create OAuth 2.0 credentials (Desktop app type)
- Run:
ytmusicapi oauth- Enter your Google OAuth client ID and secret (NOT your Spotify credentials)
This will create an oauth.json file automatically.
Note: The script automatically looks for oauth.json or browser.json. If you want to use a custom filename, specify it in your config.json:
{
"youtube_music": {
"headers_file": "custom_filename.json"
}
}To receive email notifications about playlist exports and updates, add email configuration to your config.json:
{
"spotify": {
"client_id": "your_spotify_client_id_here",
"client_secret": "your_spotify_client_secret_here",
"redirect_uri": "http://localhost:8888/callback"
},
"email": {
"enabled": true,
"smtp_server": "smtp.gmail.com",
"smtp_port": 465,
"sender_email": "your_email@gmail.com",
"sender_password": "your_app_password_here",
"recipient_email": "your_email@gmail.com",
"use_tls": true
}
}Gmail Users: For Gmail, you'll need to use an App Password instead of your regular password:
- Go to your Google Account settings
- Enable 2-Step Verification if not already enabled
- Go to Security → App passwords
- Generate a new app password for "Mail"
- Use this password in the
sender_passwordfield
Note: Port 465 (SSL) is recommended for Gmail as it's more reliable than port 587 (STARTTLS) on some networks. If you experience timeout issues, make sure you're using port 465.
Email Notifications Include:
- Export/update start notifications
- Completion notifications with statistics (tracks found, not found, success rate)
- Error notifications if something goes wrong
- Backup file locations
- List of tracks that couldn't be found
Disable emails for a single run:
python3 spotify_to_youtube.py PLAYLIST_ID --no-emailList your Spotify playlists:
python3 spotify_to_youtube.py --list-spotifyThis will display:
- Playlist name
- Playlist ID
- Number of tracks
- Owner
- Privacy status (Public/Private)
- Direct URL
List your YouTube Music playlists:
python3 spotify_to_youtube.py --list-youtubeThis will display:
- Playlist name
- Playlist ID (needed for
--update) - Number of tracks
- Direct URL
Export a Spotify playlist (defaults to PRIVATE on YouTube Music):
python3 spotify_to_youtube.py "https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M"Or use just the playlist ID:
python3 spotify_to_youtube.py 37i9dQZF1DXcBWIGoYBM5Mpython3 spotify_to_youtube.py PLAYLIST_ID --privacy PUBLIC
python3 spotify_to_youtube.py PLAYLIST_ID --privacy UNLISTEDTo update an existing YouTube Music playlist to match your Spotify playlist:
python3 spotify_to_youtube.py SPOTIFY_PLAYLIST_ID --update YOUTUBE_MUSIC_PLAYLIST_IDHow it works:
- Fetches the current YouTube Music playlist
- Creates a backup (saved to
backups/directory with timestamp) - Compares with the Spotify playlist to find differences
- Removes songs that are no longer in Spotify
- Adds new songs from Spotify that aren't in YouTube Music
- Shows a summary of changes
Skip backup (not recommended):
python3 spotify_to_youtube.py SPOTIFY_ID --update YT_PLAYLIST_ID --no-backupFinding your YouTube Music playlist ID:
Method 1: Use the --list-youtube flag (Easiest)
python3 spotify_to_youtube.py --list-youtubeMethod 2: Manually from YouTube Music
- Open the playlist in YouTube Music
- The URL will look like:
https://music.youtube.com/playlist?list=PLxxxxxxxxxxxxxx - Copy the part after
list=(e.g.,PLxxxxxxxxxxxxxx)
Method 1: Use the --list-spotify flag (Easiest)
python3 spotify_to_youtube.py --list-spotifyMethod 2: Manually from Spotify
- Open Spotify and navigate to your playlist
- Click the three dots (...) menu
- Select "Share" → "Copy link to playlist"
- The URL will look like:
https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M - You can use the full URL or just the ID part (
37i9dQZF1DXcBWIGoYBM5M)
- Fetches Spotify Playlist: Connects to Spotify API and retrieves all tracks from the specified playlist
- Searches YouTube Music: For each track, searches YouTube Music using the track name and artist
- Matches Songs: Finds the best match for each track (currently uses the first search result)
- Creates Playlist: Creates a new playlist on YouTube Music with the same name
- Adds Tracks: Adds all matched tracks to the new playlist
- Fetches Both Playlists: Gets the current state of both Spotify and YouTube Music playlists
- Creates Backup: Saves the current YouTube Music playlist to
backups/directory (unless--no-backupis used) - Compares Playlists: Intelligently compares track names and artists to find differences
- Removes Old Tracks: Deletes songs from YouTube Music that are no longer in the Spotify playlist
- Adds New Tracks: Searches for and adds new songs from Spotify that aren't in YouTube Music yet
- Reports Results: Shows summary of changes and backup location
Backup files are stored in the backups/ directory with the format:
playlist_backup_{playlist_name}_{playlist_id}_{timestamp}.json
These backups can be used to restore your playlist if something goes wrong.
- Make sure your Client ID and Client Secret are correct
- Verify the Redirect URI in your Spotify app settings matches exactly:
http://localhost:8888/callback - On first run, a browser window will open for you to authorize the app
- Make sure
headers_auth.json(oroauth.json) exists in the same directory as the script - If using browser headers, ensure you're logged into YouTube Music when extracting headers
- Headers may expire after a while; regenerate if needed
Some tracks may not be found on YouTube Music because:
- They're not available in your region
- The track/artist name differs between platforms
- The track is a Spotify exclusive
- Search matching failed (rare)
The script will report which tracks couldn't be found at the end.
- PRIVATE: Only you can see the playlist (default)
- UNLISTED: Anyone with the link can see the playlist
- PUBLIC: Anyone can find and see the playlist
- Local files in Spotify playlists are skipped
- Song matching is based on text search and may not always be 100% accurate
- YouTube Music API rate limits may apply for very large playlists
Feel free to submit issues or pull requests for improvements.
MIT License - feel free to use and modify as needed.