Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/wrestleuniverse.py (Python)

Code before:
    _API_PATH = None
    _TOKEN = None
    _TOKEN_EXPIRY = None

    def _get_token_cookie(self):
        if not self._TOKEN or not self._TOKEN_EXPIRY:
            token_cookie = self._get_cookies('https://www.wrestle-universe.com/').get('token')
            if not token_cookie or not token_cookie.value:
                self.raise_login_required(method='cookies')
            self._TOKEN = token_cookie.value
            expiry = traverse_obj(jwt_decode_hs256(self._TOKEN), ('exp', {int_or_none}))
            if not expiry:
                raise ExtractorError('There was a problem with the token cookie')
            self._TOKEN_EXPIRY = expiry

        if self._TOKEN_EXPIRY <= int(time.time()):
            raise ExtractorError(
                'Expired token. Refresh your cookies in browser and try again', expected=True)

        return self._TOKEN

    def _call_api(self, video_id, param='', msg='API', auth=True, data=None, query={}, fatal=True):
        headers = {'CA-CID': ''}
        if data:
            headers['Content-Type'] = 'application/json;charset=utf-8'
            data = json.dumps(data, separators=(',', ':')).encode('utf-8')
        if auth:
            headers['Authorization'] = f'Bearer {self._get_token_cookie()}'
        return self._download_json(
            f'https://api.wrestle-universe.com/v1/{self._API_PATH}/{video_id}{param}', video_id,
            note=f'Downloading {msg} JSON', errnote=f'Failed to download {msg} JSON',
            data=data, headers=headers, query=query, fatal=fatal)

    def _call_encrypted_api(self, video_id, param='', msg='API', data={}, query={}, fatal=True):
        # TODO: Use `dependencies.cryptodome`
        from Cryptodome.Cipher import PKCS1_OAEP
        from Cryptodome.Hash import SHA1
        from Cryptodome.PublicKey import RSA

        private_key = RSA.generate(2048)
        cipher = PKCS1_OAEP.new(private_key, hashAlgo=SHA1)

        def decrypt(data):
            if not data:
                return None
            try:
                return cipher.decrypt(base64.b64decode(data)).decode()
            except (ValueError, binascii.Error) as e:
                raise ExtractorError(f'Could not decrypt data: {e}')

        token = base64.b64encode(private_key.public_key().export_key('DER')).decode()

Review comment (suggestion):
```suggestion
            data = json.dumps(data, separators=(',', ':')).encode()
```
is default in py3

Code after:
class WrestleUniverseBaseIE(InfoExtractor):
    _VALID_URL_TMPL = r'https?://(?:www\.)?wrestle-universe\.com/(?:(?P<lang>\w{2})/)?%s/(?P<id>\w+)'
    _API_PATH = None
    _TOKEN = None
    _TOKEN_EXPIRY = None

    def _get_token_cookie(self):
        if not self._TOKEN or not self._TOKEN_EXPIRY:
            self._TOKEN = try_call(lambda: self._get_cookies('https://www.wrestle-universe.com/')['token'].value)
            if not self._TOKEN:
                self.raise_login_required()
            expiry = traverse_obj(jwt_decode_hs256(self._TOKEN), ('exp', {int_or_none}))
            if not expiry:
                raise ExtractorError('There was a problem with the token cookie')
            self._TOKEN_EXPIRY = expiry

        if self._TOKEN_EXPIRY <= int(time.time()):
            raise ExtractorError(
                'Expired token. Refresh your cookies in browser and try again', expected=True)

        return self._TOKEN

    def _call_api(self, video_id, param='', msg='API', auth=True, data=None, query={}, fatal=True):
        headers = {'CA-CID': ''}
        if data:
            headers['Content-Type'] = 'application/json;charset=utf-8'
            data = json.dumps(data, separators=(',', ':')).encode()
        if auth:
            headers['Authorization'] = f'Bearer {self._get_token_cookie()}'
        return self._download_json(
            f'https://api.wrestle-universe.com/v1/{self._API_PATH}/{video_id}{param}', video_id,
            note=f'Downloading {msg} JSON', errnote=f'Failed to download {msg} JSON',
            data=data, headers=headers, query=query, fatal=fatal)

    def _call_encrypted_api(self, video_id, param='', msg='API', data={}, query={}, fatal=True):
        if not Cryptodome:
            raise ExtractorError('pycryptodomex not found. Please install', expected=True)
        private_key = Cryptodome.PublicKey.RSA.generate(2048)
        cipher = Cryptodome.Cipher.PKCS1_OAEP.new(private_key, hashAlgo=Cryptodome.Hash.SHA1)

        def decrypt(data):
            if not data:
                return None
            try:
                return cipher.decrypt(base64.b64decode(data)).decode()
            except (ValueError, binascii.Error) as e:
                raise ExtractorError(f'Could not decrypt data: {e}')

        token = base64.b64encode(private_key.public_key().export_key('DER')).decode()
        api_json = self._call_api(video_id, param, msg, data={
            # 'deviceId' (random uuid4 generated at login) is not required yet