Esempio n. 1
0
    def _login(self):
        creds = Credentials()

        if not creds.are_filled_in():
            KodiWrapper.dialog_ok(KodiWrapper.get_localized_string(32014),
                                  KodiWrapper.get_localized_string(32015))
            KodiWrapper.open_settings()
            creds.reload()

        resp = self.session.post(
            "https://login.prd.telenet.be/openid/login.do",
            data=login_payload(creds.username, creds.password))

        last_response = resp.history[-1]

        try:
            self.auth_tries += 1

            if "Location" in last_response.headers:
                token = self.extract_auth_token(
                    last_response.headers.get('Location'))
                if not token:
                    raise NotAuthorizedException()
                PluginCache.set_data({"auth_token": token})
                return True
        except NotAuthorizedException:
            KodiWrapper.dialog_ok(KodiWrapper.get_localized_string(32006),
                                  KodiWrapper.get_localized_string(32007))

            if self.auth_tries < 2:
                KodiWrapper.open_settings()
                self._execute_required_steps()

        return False
Esempio n. 2
0
    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 refresh_epg():
    KodiWrapper.dialog_ok(
        KodiWrapper.get_localized_string(40001),  # Info
        KodiWrapper.get_localized_string(40003))  # This can take a while
    BackgroundService.cache_channel_epg()
    KodiWrapper.dialog_ok(
        KodiWrapper.get_localized_string(40001),  # Info
        KodiWrapper.get_localized_string(40002))  # EPG has been renewed
Esempio n. 4
0
 def _display_error_message(response_data):
     title, message = YeloErrors.get_error_message(
         response_data["errors"][0]["code"])
     KodiWrapper.dialog_ok(title, message)
Esempio n. 5
0
def refresh_epg():
    KodiWrapper.dialog_ok(KodiWrapper.get_localized_string(40001),
                          KodiWrapper.get_localized_string(40003))
    BackgroundService.cache_channel_epg()
    KodiWrapper.dialog_ok(KodiWrapper.get_localized_string(40001),
                          KodiWrapper.get_localized_string(40002))