mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 01:03:53 +00:00
Player endpoints example and test
This commit is contained in:
parent
125267fa4e
commit
9ed584b398
20
examples/player.py
Normal file
20
examples/player.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import spotipy
|
||||||
|
from spotipy.oauth2 import SpotifyOAuth
|
||||||
|
from pprint import pprint
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
sp = spotipy.Spotify(client_credentials_manager=SpotifyOAuth(scope="user-read-playback-state,user-modify-playback-state"))
|
||||||
|
|
||||||
|
# Shows playing devices
|
||||||
|
res = sp.devices()
|
||||||
|
pprint(res)
|
||||||
|
|
||||||
|
# Change track
|
||||||
|
sp.start_playback(uris=['spotify:track:6gdLoMygLsgktydTQ71b15'])
|
||||||
|
|
||||||
|
# Change volume
|
||||||
|
sp.volume(100)
|
||||||
|
sleep(2)
|
||||||
|
sp.volume(50)
|
||||||
|
sleep(2)
|
||||||
|
sp.volume(100)
|
||||||
@ -387,3 +387,8 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
pl = self.spotify.user_playlist_tracks(None, self.playlist, limit=2)
|
pl = self.spotify.user_playlist_tracks(None, self.playlist, limit=2)
|
||||||
self.assertTrue(len(pl["items"]) == 2)
|
self.assertTrue(len(pl["items"]) == 2)
|
||||||
self.assertTrue(pl["total"] > 0)
|
self.assertTrue(pl["total"] > 0)
|
||||||
|
|
||||||
|
def test_devices(self):
|
||||||
|
# No devices playing by default
|
||||||
|
res = self.spotify.devices()
|
||||||
|
self.assertEqual(len(res["devices"]), 0)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user