Ejemplo n.º 1
0
    def sign_resource(self, provider_id, resource_id, video_id, player,
                      version):
        proxy = control.proxy_url
        proxy = None if proxy is None or proxy == '' else {
            'http': proxy,
            'https': proxy,
        }

        credentials = auth_helper.get_globosat_cookie(provider_id)

        hash_url = 'https://security.video.globo.com/videos/%s/hash?resource_id=%s&version=%s&player=%s' % (
            video_id, resource_id, PLAYER_VERSION, PLAYER_SLUG)
        hash_json = client.request(hash_url,
                                   cookie=credentials,
                                   mobile=True,
                                   headers={"Accept-Encoding": "gzip"},
                                   proxy=proxy)

        if not hash_json or hash_json is None or 'message' in hash_json and hash_json[
                'message']:
            control.infoDialog(message=control.lang(34102).encode('utf-8'),
                               sound=True,
                               icon='ERROR')
            return None

        hash = util.get_signed_hashes(hash_json['hash'])[0]

        return hash, hash_json[
            "user"] if 'user' in hash_json else None, credentials
Ejemplo n.º 2
0
    def sign_resource(self,
                      provider_id,
                      resource_id,
                      video_id,
                      player,
                      version,
                      cdn=None):
        proxy = control.proxy_url
        proxy = None if proxy is None or proxy == '' else {
            'http': proxy,
            'https': proxy,
        }

        credentials = auth_helper.get_globosat_cookie(provider_id)

        hash_url = 'https://security.video.globo.com/videos/%s/hash?resource_id=%s&version=%s&player=%s' % (
            video_id, resource_id, PLAYER_VERSION, PLAYER_SLUG)
        if cdn:
            hash_url = hash_url + '&cdn=' + cdn
        control.log('GET %s' % hash_url)
        response = requests.get(hash_url,
                                cookies=credentials,
                                headers={"Accept-Encoding": "gzip"},
                                proxies=proxy)
        response.raise_for_status()

        hash_json = response.json()

        control.log(hash_json)

        if not hash_json or hash_json is None or 'message' in hash_json and hash_json[
                'message']:
            message = hash_json[
                'message'] if hash_json and 'message' in hash_json else control.lang(
                    34102)
            message = str(
                hash_json['http_status_code']) + u'|' + message.encode(
                    'utf-8'
                ) if hash_json and 'http_status_code' in hash_json else message
            control.infoDialog(message=message.encode('utf-8'),
                               sound=True,
                               icon='ERROR')
            raise Exception(message)

        hash_token = util.get_signed_hashes(
            hash_json['hash']
        )[0] if 'hash' in hash_json else hash_json['token']
        user = hash_json["user"] if 'user' in hash_json else None
        return hash_token, user, credentials