def _get_oesp_token(self): refresh_token = PluginCache.get_by_key("refreshToken") json_payload = { "refreshToken": refresh_token, "username": self.username } r = Utils.make_request( self.session, method="POST", url= "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/session?token=true", headers=self.construct_header(), data=json_payload) json_data = r.json() oesp_token = json_data["oespToken"] shared_profile_id = json_data["customer"]["sharedProfileId"] entitlements = json_data["entitlements"] PluginCache.set_data({ "oespToken": oesp_token, "sharedProfileId": shared_profile_id, "entitlements": entitlements })
def clear_streams(self): r = Utils.make_request( self.session, method="POST", url= "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/playback/clearstreams", headers=self.construct_header())
def _get_refresh_token(self): token = PluginCache.get_by_key("token") validity_token = PluginCache.get_by_key("validityToken") state = PluginCache.get_by_key("state") json_payload = { "authorizationGrant": { "authorizationCode": token, "validityToken": validity_token, "state": state } } r = Utils.make_request( self.session, method="POST", url= "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/authorization", headers=self.construct_header(), data=json_payload) json_data = r.json() refresh_token = json_data["refreshToken"] PluginCache.set_data({ "refreshToken": refresh_token, })
def refresh_token(self): r = Utils.make_request( self.session, method="GET", url="https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/session", headers=self.construct_header()) json_data = r.json() oesp_token = json_data["oespToken"] PluginCache.set_data({"oespToken": oesp_token})
def _check_registered_devices(self): r = Utils.make_request( self.session, method="GET", url= "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/devices/status", headers=self.construct_header()) json_data = r.json() return json_data
def get_program_schedule(self, station_id): timestamp = int(time.time()) r = Utils.make_request( self.session, method="GET", url="https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/listings?" "byEndTime={}~" "&byStationId={}" "&range=1-1&sort=startTime".format(timestamp, station_id), headers={'User-Agent': self.USER_AGENT}) json_data = r.json() program = json_data["listings"][0]["program"] return program
def web_authorization(self): r = Utils.make_request( self.session, method="GET", url= "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/authorization", headers=self.construct_header()) json_data = r.json() self.authorization_uri = json_data["session"]["authorizationUri"] validity_token = json_data["session"]["validityToken"] state = json_data["session"]["state"] PluginCache.set_data({"validityToken": validity_token, "state": state})
def _request_license_token(self, content_locator): json_payload = {"contentLocator": content_locator} r = Utils.make_request( self.session, method="POST", url= "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/license/token", headers=self.construct_header(), data=json_payload) try: json_data = r.json() except ValueError: json_data = "" return r.status_code, json_data
def _register_device(self, device_id): json_payload = { "deviceId": device_id, "deviceName": DEVICE_NAME, "customerDefinedName": DEVICE_NAME, "deviceClass": DEVICE_CLASS } r = Utils.make_request( self.session, method="POST", url="https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/devices", headers=self.construct_header(), data=json_payload) if r.status_code != 204: self.logger.error( "An error has occurred trying to register the device.")
def replace_registered_device(self, old_device_id, new_device_id): json_payload = { "deviceId": new_device_id, "deviceName": DEVICE_NAME, "customerDefinedName": DEVICE_NAME, "deviceClass": DEVICE_CLASS } r = Utils.make_request( self.session, method="PUT", url= "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/devices/{}". format(old_device_id), headers=self.construct_header(), data=json_payload) json_data = r.json() return json_data["deviceId"]
def login(self): r = Utils.make_request( self.session, method="POST", url="https://login.prd.telenet.be/openid/login.do", headers=self.construct_header( content_type="application/x-www-form-urlencoded"), data={ 'j_username': '******'.format(self.username), 'j_password': '******'.format(self.passwd), 'rememberme': 'true' }, is_json=False) last_response = r.history[-1] if "Location" in last_response.headers: token = Utils.extract_auth_token( last_response.headers.get('Location')) PluginCache.set_data({"token": token, "username": self.username})
def get_server_certificate(self, content_locator): r = Utils.make_request( self.session, method="POST", url= "https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/license/eme", headers={ "User-Agent": self.USER_AGENT, "Connection": 'keep-alive', "Referer": "https://www.telenettv.be/", "Content-Type": "application/octet-stream", "X-OESP-Content-Locator": content_locator, "X-OESP-DRM-SchemeIdUri": "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed", "X-OESP-License-Token": self.license_token, "X-OESP-License-Token-Type": "velocix", "X-OESP-Token": self.oesp_token, "X-OESP-Username": self.username }, data="\b\x04", is_json=False) return base64.b64encode(r.content)
def get_channels(self): r = Utils.make_request( self.session, method="GET", headers=self.construct_header(), url="https://obo-prod.oesp.telenettv.be/oesp/v4/BE/nld/web/channels?" "includeInvisible=false" "&sort=channelNumber") json_data = r.json() useful_channel_data = [] entitlements = PluginCache.get_by_key("entitlements") if not entitlements: return useful_channel_data if "channels" in json_data: fetched_channel_data = json_data["channels"] for channel_data in fetched_channel_data: station = channel_data["stationSchedules"][0]["station"] video_streams = station["videoStreams"] if video_streams: channel = Channel(channel_data["id"], station["id"], channel_data["title"], channel_data["channelNumber"], bool(station["hasLiveStream"]), station["entitlements"]) if not any(x in entitlements for x in channel.entitlements): continue HLS_stream = {} DASH_stream = {} HSS_stream = {} for video_stream in video_streams: if "Orion-HLS" in video_stream["assetTypes"]: HLS_stream = Stream(video_stream["streamingUrl"], video_stream["contentLocator"], video_stream["protectionKey"]) if "Orion-DASH" in video_stream["assetTypes"]: DASH_stream = Stream( video_stream["streamingUrl"], video_stream["contentLocator"], video_stream["protectionKey"]) if "Orion-HSS" in video_stream["assetTypes"]: HSS_stream = Stream(video_stream["streamingUrl"], video_stream["contentLocator"], video_stream["protectionKey"]) thumbnail = [ img["url"] for img in station["images"] if img["assetType"] == "station-logo-xlarge" ][0] imageStream = [ img["url"] for img in station["images"] if img["assetType"] == "imageStream" ][0] channel.thumbnail = thumbnail channel.stream_thumbnail = imageStream channel.stream_DASH = DASH_stream channel.stream_HLS = HLS_stream channel.stream_HSS = HSS_stream useful_channel_data.append(channel) return useful_channel_data
def authorize(self): Utils.make_request(self.session, method="GET", url=self.authorization_uri, headers={'User-Agent': self.USER_AGENT}, allow_redirects=False)