コード例 #1
0
    def _login(self, url, payload, params=None):
        data = self._session.post(url, data=payload, params=params).json()

        if 'errors' in data:
            try:
                msg = data['errors'][0]['code']
                if msg == 'Streamco.Login.VPNDetected':
                    msg = _.IP_ADDRESS_ERROR
            except:
                msg = ''

            raise APIError(_(_.LOGIN_ERROR, msg=msg))

        userdata.set('token', data['jwToken'])
        userdata.set('expires',
                     int(time.time() + (data['renew'] - data['now']) - 30))
        userdata.set('user_id', data['userId'])

        userdata.set('profile_id', data['profile']['id'])
        userdata.set('profile_name', data['profile']['name'])
        userdata.set('profile_icon', data['profile']['iconImage']['url'])
        userdata.set('profile_kids',
                     int(data['profile'].get('isKidsProfile', False)))

        self._set_authentication()

        try:
            log.debug('Token Data: {}'.format(
                json.dumps(jwt_data(userdata.get('token')))))
        except:
            pass
コード例 #2
0
    def _set_languages(self):
        self._app_language = 'en'
        self._playback_language = 'en'
        self._subtitle_language = 'en'
        self._kids_mode = False
        self._maturity_rating = 9999
        self._region = None

        if not self.logged_in:
            return

        token = userdata.get('access_token')
        if '..' in token:  #JWE Token
            return

        data = jwt_data(token)['context']

        #   self._maturity_rating = data['preferred_maturity_rating']['implied_maturity_rating']
        #   self._region = data['location']['country_code']

        for profile in data['profiles']:
            if profile['id'] == data['active_profile_id']:
                self._app_language = profile['language_preferences'][
                    'app_language']
                self._playback_language = profile['language_preferences'][
                    'playback_language']
                self._subtitle_language = profile['language_preferences'][
                    'subtitle_language']
                self._kids_mode = profile['kids_mode_enabled']
                return
コード例 #3
0
ファイル: api.py プロジェクト: matthuisman/slyguy.addons
    def _set_token(self, token):
        data = jwt_data(token)
        expires = min(int(time.time() + 86400), data['exp'] - 10)

        userdata.set('expires', expires)
        userdata.set('token', token)

        self._set_authentication()
コード例 #4
0
ファイル: api.py プロジェクト: matthuisman/slyguy.addons
    def _parse_tokens(self, access_token, id_token):
        jwt = jwt_data(access_token)

        userdata.set('access_token', access_token)
        userdata.set('id_token', id_token)
        userdata.set('token_expires',
                     int(time.time()) + (jwt['exp'] - jwt['iat'] - 30))
        userdata.set('country', jwt['country'])
        userdata.set('package', jwt['package'])

        self._set_access_token(access_token)
コード例 #5
0
    def _process_token(self, data):
        if 'error' in data:
            raise APIError(data['error'])

        userdata.set('access_token', data['authorizationToken'])
        if 'refreshToken' in data:
            userdata.set('refresh_token', data['refreshToken'])

        token_data = jwt_data(data['authorizationToken'])
        userdata.set('expires', int(time()+(token_data['exp']-token_data['iat']-30)))

        self._set_authentication()
コード例 #6
0
    def _vhx_token(self):
        token = mem_cache.get('vhx_token')
        if token:
            return token

        page = self._session.get('/').text.replace(' ', '').strip()
        token = re.search('TOKEN="(.*?)"', page).group(1)
        data = jwt_data(token)
        expires_in = int(data['exp'] - time.time()) - 30
        mem_cache.set('vhx_token', token, expires_in)

        return token
コード例 #7
0
    def _refresh_token(self, force=False):
        token = userdata.get('auth_token')
        if token and not force and userdata.get('expires', 0) > time():
            self._set_auth(token)
            return

        log.debug('Refreshing token' if token else 'Fetching token')

        key = userdata.get('key')
        data = self._session.post('https://api.watchnebula.com/api/v1/authorization/', params={'from': 'Android'}, json={}, headers={'Authorization': 'Token {}'.format(key)}).json()

        token = data['token']
        jwt = jwt_data(token)

        userdata.set('auth_token', token)
        userdata.set('expires', jwt['exp'] - 10)

        self._set_auth(token)
コード例 #8
0
ファイル: api.py プロジェクト: Raspifan2020/slyguy.addons
    def _process_login(self, resp):
        data = resp.json()

        if not resp.ok or 'sky-access' not in resp.cookies:
            raise APIError(_(_.LOGIN_ERROR, message=data.get('message')))

        token = resp.cookies['sky-access']

        userdata.set('sky_token', token)
        userdata.set('device_id', data['deviceId'])

        if 'profileId' in data:
            userdata.set('profile_id', data['profileId'])

        jwt = jwt_data(token)
        userdata.set('token_expires', jwt['exp'])

        self._set_authentication()
        self._get_play_token()
        self._subscriptions()
コード例 #9
0
ファイル: api.py プロジェクト: Raspifan2020/slyguy.addons
    def _oauth_token(self, payload):
        token_data = self._session.post('https://login.sky.co.nz/oauth/token',
                                        json=payload,
                                        error_msg=_.TOKEN_ERROR).json()

        if 'error' in token_data:
            error = _.REFRESH_TOKEN_ERROR if data.get(
                'grant_type') == 'refresh_token' else _.LOGIN_ERROR
            raise APIError(_(error, msg=token_data.get('error_description')))

        userdata.set('access_token', token_data['access_token'])
        userdata.set('expires', int(time() + token_data['expires_in'] - 15))
        if 'refresh_token' in token_data:
            userdata.set('refresh_token', token_data['refresh_token'])

        #Force 1st profile
        data = jwt_data(token_data['access_token'])
        profile_id = data['https://skygo.co.nz/profiles'][0]['id']
        userdata.set('profile_id', profile_id)
        ####

        self._set_authentication()
コード例 #10
0
ファイル: api.py プロジェクト: matthuisman/slyguy.addons
 def _set_token(self, jwt_token):
     userdata.set('jwt_token', jwt_token)
     data = jwt_data(jwt_token)
     userdata.set('expires', data['exp'] - 2592000)
     self._set_authentication()
コード例 #11
0
 def _set_auth(self, auth_token):
     token_data = jwt_data(auth_token)
     userdata.set('auth_token', auth_token)
     userdata.set('token_expires', token_data['exp'] - 30)
     self._set_authentication()