def test_get_user_agent_Windows(self, mock_system): """ADD ME""" mock_system.return_value = 'Windows' utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertIn( container=utils.get_user_agent(), member='Win')
def test_get_use_inputstream_high_inputstream(self, mock_executeJSONRPC, mock_executeJSONRPC2): mock_executeJSONRPC.return_value = '{"result": {"version": {"major": 18}}}' mock_executeJSONRPC2.return_value = '{"result": {"addon": {"enabled": true, "version": "12.1.7"}}}' utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertEquals( first=utils.use_inputstream(), second=False)
def test_get_use_inputstream_low_inputstream(self, mock_executeJSONRPC): mock_executeJSONRPC.return_value = '{"result": {"version": {"major": 18}}}' utils = Utils(kodi_base_url='/foo/', constants=Constants()) def return_low_version(): return '0.9.9' utils.get_inputstream_version = return_low_version self.assertEquals( first=utils.use_inputstream(), second=False)
def test_capitalize(self): """ADD ME""" utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertEquals( first=utils.capitalize('foo bar'), second='Foo Bar') self.assertEquals( first=utils.capitalize('FOO BAR'), second='Foo Bar') self.assertEquals( first=utils.capitalize('Foo Bar'), second='Foo Bar')
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 request_license_token(self, content_locator): # retry once for _ in range(2): status_code, json_data = self._request_license_token( content_locator) if status_code == 200: license_token = json_data.get("token") PluginCache.set_data({"licenseToken": license_token}) break elif status_code == 400: new_device_id = Utils.create_token(64) bad_request = BadRequest.parse_error_object(json_data) if bad_request.code == BadRequest.KnownErrorCodes.DEVICE_UNREGISTERED: self._register_device(new_device_id) PluginCache.set_data({"deviceId": new_device_id}) elif bad_request.code == BadRequest.KnownErrorCodes.DEVICE_UNREGISTERED_DEVICE_LIMIT_REACHED: # get the existing registered devices existing_devices = self.get_registered_device_list() # select a random device to swap random_device = random.choice(existing_devices) # replace registered device with the randomly selected one self.replace_registered_device(random_device.device_id, new_device_id) PluginCache.set_data({"deviceId": new_device_id})
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 _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 _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 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 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 __init__(self, customer_defined_name="", device_class="", device_id="", device_name="", device_status="", registered=0): self.customer_defined_name = customer_defined_name self.device_class = device_class self.device_id = device_id self.device_name = device_name self.device_status = device_status self.registered = Utils.get_datetime(registered)
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 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 _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 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 test_get_kodi_version_error_response(self, mock_executeJSONRPC): mock_executeJSONRPC.return_value = '{"error": true}' utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertEquals( first=utils.get_kodi_version(), second=17)
def test_get_use_inputstream_error(self, mock_executeJSONRPC): mock_executeJSONRPC.return_value = '{"error": true}' utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertEquals( first=utils.use_inputstream(), second=False)
def test_generate_hash(self): """ADD ME""" utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertEquals( first=utils.generate_hash('ABCDEFG'), second='bae3735e5822d8c30fafd70736316e7807f7cccf65e6e73c15f32a60')
def test_get_use_inputstream_setting_off(self, mock_xbmcaddon): mock_xbmcaddon.return_value = MockAddon() utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertEquals( first=utils.use_inputstream(), second=False)
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 __init__(self, stream_url, content_locator, protection_key): self.baseUrl = Utils.get_domain_url(stream_url) self.streamUrl = stream_url self.contentLocator = content_locator self.protectionKey = protection_key
def test_get_addon(self): """ADD ME""" utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertIn( container=str(utils.get_addon()), member='xbmcaddon.Addon')
def test_get_user_agent(self): """ADD ME""" utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertIn( container=utils.get_user_agent(), member='Chrome/59.0.3071.115')
def test_build_url(self): """ADD ME""" utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertIn( container=utils.build_url({'bar': 'baz'}), member='/foo/?bar=baz')
def test_get_localized_string_unicode(self, mock_xbmcaddon): mock_xbmcaddon.return_value = MockAddon() utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertEquals( first=utils.get_local_string(30001), second='Foo')
try: PLUGIN_HANDLE = int(argv[1]) KODI_BASE_URL = argv[0] except ValueError: PLUGIN_HANDLE = 1 KODI_BASE_URL = '' try: from urllib.parse import parse_qsl except: from urlparse import parse_qsl # init plugin object structure CONSTANTS = Constants() CACHE = Cache() UTILS = Utils(constants=CONSTANTS, kodi_base_url=KODI_BASE_URL) DIALOGS = Dialogs(utils=UTILS) ITEM_HELPER = ItemHelper(constants=CONSTANTS, utils=UTILS) SETTINGS = Settings(utils=UTILS, dialogs=DIALOGS, constants=CONSTANTS) SESSION = Session(constants=CONSTANTS, util=UTILS, settings=SETTINGS) CONTENT_LOADER = ContentLoader( session=SESSION, item_helper=ITEM_HELPER, cache=CACHE, handle=PLUGIN_HANDLE) def router(paramstring): """ Converts paramstrings into dicts & decides which method should be called in order to display contents
def test_get_inputstream_version_no_version(self, mock_executeJSONRPC): mock_executeJSONRPC.return_value = '{"result": {"addon": {"enabled": true}}}' utils = Utils(kodi_base_url='/foo/', constants=Constants()) self.assertEquals( first=utils.get_inputstream_version(), second='1.0.0')