This commit is contained in:
+10
@@ -90,7 +90,12 @@ class SpotifyClient:
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=self.timeout) as response:
|
||||
raw = response.read()
|
||||
# A player command (seek, say) can answer 200 with a body that is
|
||||
# not JSON at all -- it worked, there is just nothing to read.
|
||||
try:
|
||||
return json.loads(raw) if raw else {}
|
||||
except ValueError:
|
||||
return {}
|
||||
except urllib.error.HTTPError as exc:
|
||||
if exc.code == 401 and not retrying:
|
||||
# The access token can go stale between calls even inside
|
||||
@@ -135,6 +140,11 @@ class SpotifyClient:
|
||||
self._call("PUT", "/v1/me/player", body={"device_ids": [device["id"]], "play": True})
|
||||
return device
|
||||
|
||||
def seek(self, position_ms: int):
|
||||
"""Jump to position_ms in whatever the account is playing, on
|
||||
whichever device is playing it."""
|
||||
self._call("PUT", f"/v1/me/player/seek?position_ms={int(position_ms)}")
|
||||
|
||||
|
||||
def _error_detail(exc: urllib.error.HTTPError) -> str:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user