Spotify2YTMusicV2

raw JSON →
0.2.2 verified Sat May 09 auth: no python

A tool to copy Spotify playlists to YouTube Music (YTMusic). Currently at version 0.2.2, released on 2025-04-20. Release cadence is irregular; still in early development.

pip install spotify2ytmusicv2
error spotipy.exceptions.SpotifyException: http status: 400, code: -1, message: Bad request
cause Missing or invalid Spotify API credentials (client ID or secret).
fix
Ensure you have set SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET environment variables correctly.
error KeyError: 'User-Agent'
cause The YT_MUSIC_HEADERS string is missing required keys like 'User-Agent' and 'Cookie'.
fix
Copy the full headers object from browser dev tools, including all keys, and export as a JSON string.
error AttributeError: 'Spotify2YTMusic' object has no attribute 'transfer_playlist'
cause Using the old method name which was removed in version 0.2.0.
fix
Use client.copy_playlist(playlist_id) instead.
gotcha The YTMusic headers must be passed as a raw JSON string in the environment variable YT_MUSIC_HEADERS. Do not use a dictionary or file; the library expects a string.
fix Export the headers JSON as a string: export YT_MUSIC_HEADERS='{"User-Agent":"...","Cookie":"..."}'
breaking In version 0.2.0, the method `copy_playlist` was renamed from `transfer_playlist`. Calling `transfer_playlist` will raise an AttributeError.
fix Use `client.copy_playlist(...)` instead of `client.transfer_playlist(...)`.
gotcha The library expects Spotify playlist ID (not URL). Passing a full Spotify URL will fail silently or raise an error.
fix Extract the ID from the URL (e.g., '3s9t1vD1d0c2a6b8f0e4a' from 'open.spotify.com/playlist/...').

Authenticate and copy a Spotify playlist to YouTube Music. Obtain Spotify API credentials from Spotify Developer Dashboard, and YTMusic headers from browser dev tools after logging into music.youtube.com.

from spotify2ytmusicv2 import Spotify2YTMusic
import os

client = Spotify2YTMusic(
    spotify_client_id=os.environ.get('SPOTIFY_CLIENT_ID', ''),
    spotify_client_secret=os.environ.get('SPOTIFY_CLIENT_SECRET', ''),
    ytmusic_headers_raw=os.environ.get('YT_MUSIC_HEADERS', '{}')
)
playlist_id = 'your_spotify_playlist_id'
client.copy_playlist(playlist_id, public=True)