def _start_stream(self, channel, max_tries=2): resp = None for _ in range(max_tries): device_id = get_from_cache("device_id") oauth_tokens = get_from_cache("OAuthTokens") try: resp = self.session.post(BASE_URL + "/stream/start", headers={ "Content-Type": "application/json;charset=utf-8", "X-Yelo-DeviceId": device_id, "Authorization": authorization_payload(oauth_tokens["accessToken"]) }, data=stream_payload(device_id, channel)) if resp.status_code == 401: raise NotAuthorizedException("Unauthorized") break except NotAuthorizedException: self._refresh_oauth_token() if not resp: raise YeloException('Could not authenticate to play channel %s' % channel) response_data = resp.json() if response_data.get("errors"): title, message = YeloErrors.get_error_message(self.session, response_data["errors"][0]["code"]) KodiWrapper.dialog_ok(title, message) raise YeloException(message) return response_data
def _customer_features(self): device_id = get_from_cache("device_id") oauth_tokens = get_from_cache("OAuthTokens") if not oauth_tokens: return {} resp = self.session.get(BASE_URL + "/session/lookup?include=customerFeatures", headers={ "Content-Type": "application/json;charset=utf-8", "X-Yelo-DeviceId": device_id, "Authorization": authorization_payload(oauth_tokens.get('accessToken')) }) return resp.json()
def _start_stream(self, channel): response_data = None max_iterations = 2 current_iteration = 0 device_id = PluginCache.get_by_key("device_id") while current_iteration < max_iterations: oauth_tokens = PluginCache.get_by_key("OAuthTokens") try: response = self.session.post( BASE_URL + "/stream/start", headers={ "Content-Type": "application/json;charset=utf-8", "X-Yelo-DeviceId": device_id, "Authorization": authorization_payload(oauth_tokens["accessToken"]) }, data=stream_payload(device_id, channel)) try: response_data = response.json() except ValueError as exc: _LOGGER.error(exc) current_iteration += 1 if response.status_code == 401: raise NotAuthorizedException("Unauthorized") if response.status_code == 403: raise ForbiddenException("Forbidden") break except NotAuthorizedException: self._refresh_oauth_token() except ForbiddenException: stream = response_data.get('stream') if stream is None: self._display_error_message(response_data) return None if stream.get('authorizationResult') is None or stream.get( 'authorizationResult').get('resultCode').upper( ) != "DEVICE_AUTHORIZATION_REQUIRED": self._display_error_message(response_data) return None self._check_registered_devices(response_data) return response_data
def _device_authorize(self, device_id): oauth_tokens = PluginCache.get_by_key("OAuthTokens") resp = self.session.post(BASE_URL + "/device/authorize", headers={ "Content-Type": "application/json;charset=utf-8", "X-Yelo-DeviceId": device_id, "Authorization": authorization_payload( oauth_tokens["accessToken"]) }, data=device_authorize(device_id, "YeloPlay")) return resp