spotify2ytmusic

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

CLI tool and library to transfer Spotify playlists to YouTube Music. v0.9.32, active development, monthly releases.

pip install spotify2ytmusic
error spotipy.exceptions.SpotifyException: http status: 401, code: -1 - code: 401, reason: Unauthorized
cause Invalid or expired Spotify client credentials.
fix
Verify SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET from Spotify Developer Dashboard. Regenerate if needed.
error ytmusicapi.exceptions.YTMusicServerError: 401 Unauthorized
cause Incorrect or malformed YouTube Music headers_auth string.
fix
Re-export headers from browser network request to music.youtube.com and ensure the JSON string is valid (e.g., '{"cookie":"...", "x-origin":"..."}').
error KeyError: 'id' when calling transfer_playlist
cause Passing a full Spotify playlist URL instead of playlist ID.
fix
Extract the playlist ID: e.g., '37i9dQZF1DXcBWIGoYBM5M' from 'https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M'.
breaking In version 0.9.0, the `transfer_playlist` method changed from accepting Spotify playlist URL to requiring the playlist ID. URL parsing must be done manually.
fix Extract playlist ID from URL using regex or string splitting before passing to `transfer_playlist`.
gotcha YouTube Music 'headers_auth' parameter expects a JSON string of browser headers, not a simple token. Many users pass an invalid string and get 401 errors.
fix Generate headers_auth by exporting request headers from browser's developer tools (Network tab) after logging into music.youtube.com. Pass as a JSON string.
deprecated The `Spotify2YTMusic` class constructor parameter `ytmusic_auth` has been deprecated in favor of `headers_auth` since v0.9.20.
fix Use `headers_auth=...` instead of `ytmusic_auth=...`.
gotcha Spotify rate limits can cause the transfer to fail silently for large playlists (>100 tracks). The library does not handle pagination errors gracefully.
fix Split large playlists into chunks or use the `max_tracks` parameter (if available) to limit per run.

Initialize with credentials and transfer a public playlist. Requires Spotify API credentials and YouTube Music headers auth.

from spotify2ytmusic import Spotify2YTMusic

# Set environment variables or pass directly
client = Spotify2YTMusic(
    spotify_client_id=os.environ.get('SPOTIFY_CLIENT_ID', ''),
    spotify_client_secret=os.environ.get('SPOTIFY_CLIENT_SECRET', ''),
    ytmusic_auth=os.environ.get('YTMUSIC_AUTH', '')
)
# Transfer a public Spotify playlist by ID
result = client.transfer_playlist('37i9dQZF1DXcBWIGoYBM5M')
print(result)