From 9ed584b398f6055e46754af95a6a5d24f78c3216 Mon Sep 17 00:00:00 2001 From: Stephane Bruckert Date: Sat, 22 Feb 2020 11:12:29 +0000 Subject: [PATCH] Player endpoints example and test --- examples/player.py | 20 ++++++++++++++++++++ tests/integration/test_user_endpoints.py | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 examples/player.py diff --git a/examples/player.py b/examples/player.py new file mode 100644 index 0000000..97945f1 --- /dev/null +++ b/examples/player.py @@ -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) diff --git a/tests/integration/test_user_endpoints.py b/tests/integration/test_user_endpoints.py index 28f1b45..671335f 100644 --- a/tests/integration/test_user_endpoints.py +++ b/tests/integration/test_user_endpoints.py @@ -387,3 +387,8 @@ class AuthTestSpotipy(unittest.TestCase): pl = self.spotify.user_playlist_tracks(None, self.playlist, limit=2) self.assertTrue(len(pl["items"]) == 2) self.assertTrue(pl["total"] > 0) + + def test_devices(self): + # No devices playing by default + res = self.spotify.devices() + self.assertEqual(len(res["devices"]), 0)