added play by uris to play

This commit is contained in:
aj 2019-08-12 00:34:25 +01:00
parent 37328b8a58
commit 22d22b4d9d

View File

@ -39,7 +39,7 @@ class Network:
logger.debug(f'{method} post {req.status_code}') logger.debug(f'{method} post {req.status_code}')
return req return req
else: else:
error_text = req.json()['error']['message'] error_text = str(req.text)
logger.error(f'{method} post {req.status_code} {error_text}') logger.error(f'{method} post {req.status_code} {error_text}')
return None return None
@ -54,7 +54,7 @@ class Network:
logger.debug(f'{method} put {req.status_code}') logger.debug(f'{method} put {req.status_code}')
return req return req
else: else:
error_text = req.json()['error']['message'] error_text = str(req.text)
logger.error(f'{method} put {req.status_code} {error_text}') logger.error(f'{method} put {req.status_code} {error_text}')
return None return None
@ -153,7 +153,7 @@ class Network:
return next((i for i in self.get_available_devices()['devices'] if i['name'] == devicename), None)['id'] return next((i for i in self.get_available_devices()['devices'] if i['name'] == devicename), None)['id']
def play(self, uri, deviceid=None): def play(self, uri=None, uris=None, deviceid=None):
logger.info(f"{uri}{' ' + deviceid if deviceid is not None else ''}") logger.info(f"{uri}{' ' + deviceid if deviceid is not None else ''}")
@ -162,8 +162,18 @@ class Network:
else: else:
params = None params = None
if uri and uris:
raise Exception('wont take both context uri and uris')
if uri:
payload = {'context_uri': uri} payload = {'context_uri': uri}
if uris:
payload = {'uris': uris[:200]}
if not uri and not uris:
raise Exception('need either context uri or uris')
req = self._make_put_request('play', 'me/player/play', params=params, json=payload) req = self._make_put_request('play', 'me/player/play', params=params, json=payload)
def pause(self, deviceid=None): def pause(self, deviceid=None):