Ejemplo n.º 1
0
    def _get_cached_token(self, token_name, token_variant=None):
        """Return a cached token"""
        path = self._get_token_path(token_name, token_variant)

        if not exists(path):
            return None

        with open_file(path) as fdesc:
            token = get_json_data(fdesc)

        if token is None:
            return None

        from datetime import datetime
        import dateutil.parser
        import dateutil.tz
        now = datetime.now(dateutil.tz.tzlocal())
        exp = dateutil.parser.parse(token.get('expirationDate'))
        if exp <= now:
            log(2, "Token expired, cached token '{path}' deleted", path=path)
            delete(path)
            return None

        log(3, "Got cached token '{path}'", path=path)
        return token.get(token_name)
Ejemplo n.º 2
0
    def get_playertoken(self, token_url, token_variant=None, roaming=False):
        ''' Get cached or new playertoken, variants: live or ondemand '''
        token = None
        xvrttoken_variant = None
        if roaming:
            xvrttoken_variant = 'roaming'
            # Delete cached playertoken
            path = self._get_token_path('vrtPlayerToken', token_variant)
            delete(path)
        else:
            token = self._get_cached_token('vrtPlayerToken', token_variant)

        if token is None:
            if token_variant == 'ondemand' or roaming:
                xvrttoken = self.get_xvrttoken(token_variant=xvrttoken_variant)
                if xvrttoken is None:
                    return token
                cookie_value = 'X-VRT-Token=' + xvrttoken
                headers = {
                    'Content-Type': 'application/json',
                    'Cookie': cookie_value
                }
            else:
                headers = {'Content-Type': 'application/json'}
            token = self._get_new_playertoken(token_url, headers,
                                              token_variant)

        return token
Ejemplo n.º 3
0
 def delete_tokens():
     """Delete all cached tokens"""
     # Remove old tokens
     # FIXME: Deprecate and simplify this part in a future version
     _, files = listdir(addon_profile())
     token_files = [item for item in files if item.endswith('.tkn')]
     # Empty userdata/tokens/ directory
     if exists(get_tokens_path()):
         _, files = listdir(get_tokens_path())
         token_files += ['tokens/' + item for item in files]
     if token_files:
         for item in token_files:
             delete(addon_profile() + item)
         notification(message=localize(30985))
Ejemplo n.º 4
0
 def delete_tokens():
     ''' Delete all cached tokens '''
     # Remove old tokens
     # FIXME: Deprecate and simplify this part in a future version
     dirs, files = listdir(get_userdata_path())  # pylint: disable=unused-variable
     token_files = [item for item in files if item.endswith('.tkn')]
     # Empty userdata/tokens/ directory
     if exists(get_tokens_path()):
         dirs, files = listdir(get_tokens_path())  # pylint: disable=unused-variable
         token_files += ['tokens/' + item for item in files]
     if token_files:
         for item in token_files:
             delete(get_userdata_path() + item)
         notification(message=localize(30985))
Ejemplo n.º 5
0
    def _get_cached_token(self, token_name, token_variant=None):
        ''' Return a cached token '''
        from json import load
        cached_token = None
        path = self._get_token_path(token_name, token_variant)

        if exists(path):
            from datetime import datetime
            import dateutil.parser
            import dateutil.tz
            with open_file(path) as fdesc:
                token = load(fdesc)
            now = datetime.now(dateutil.tz.tzlocal())
            exp = dateutil.parser.parse(token.get('expirationDate'))
            if exp > now:
                log(3, "Got cached token '{path}'", path=path)
                cached_token = token.get(token_name)
            else:
                log(2, "Cached token '{path}' deleted", path=path)
                delete(path)
        return cached_token