Skip to content

Instantly share code, notes, and snippets.

@tbuwadi
Last active February 5, 2022 06:09
Show Gist options
  • Save tbuwadi/2ea4c4ac899eb81328ed95a68787248c to your computer and use it in GitHub Desktop.
Save tbuwadi/2ea4c4ac899eb81328ed95a68787248c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from time import sleep
DEVICE_ID="YOUR_DEVICE_ID"
CLIENT_ID="YOUR_CLIENT_ID"
CLIENT_SECRET="YOUR_CLIENT_SECRET"
# Spotify Authentication
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
redirect_uri="http://localhost:8080",
scope="user-read-playback-state,user-modify-playback-state"))
# Transfer playback to the Raspberry Pi if music is playing on a different device
sp.transfer_playback(device_id=DEVICE_ID, force_play=False)
# Play the spotify track at URI with ID 45vW6Apg3QwawKzBi03rgD (you can swap this for a diff song ID below)
sp.start_playback(device_id=DEVICE_ID, uris=['spotify:track:45vW6Apg3QwawKzBi03rgD'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment