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

Code before:
        {
            # VIP-restricted audio
            'url': 'https://www.ximalaya.com/sound/562111701',
            'only_matching': True,
        },
    ]

    @staticmethod
    def _decrypt_filename(audio_info):
        seed = float_or_none(audio_info['seed'])
        file_id = audio_info['fileId']
        cgstr = ''
        key = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\\:._-1234567890'
        for _ in range(len(key)):
            j = 211 * seed + 30031
            seed = float_or_none(int_or_none(j) % 65536)
            ran = seed / float_or_none(65536)
            r = int_or_none(ran * float_or_none(len(key)))
            cgstr += key[r]
            key = key.replace(key[r], '')
        strs = file_id.split('*')
        filename = ''
        for n in range(len(strs) - 1):
            if strs[n] != '':
                index = int_or_none(strs[n])
                filename += cgstr[index]
        if filename[0] != '/':
            filename = '/' + filename
        return filename

    @staticmethod
    def _decrypt_url_params(audio_info):
        def char_code_at(s: str, n: int) -> int:
            return ord(s[n]) if n < len(s) else 0

        def decrypt(e: str, t: list) -> str:
            r = list(range(256))
            a = 0
            s = ''

            for o in range(256):
                a = (a + r[o] + int_or_none(char_code_at(e, o % len(e)))) % 256
                r[o], r[a] = r[a], r[o]

            a, o = 0, 0
            for u in range(len(t)):
                o = (o + 1) % 256
                a = (a + r[o]) % 256
                r[o], r[a] = r[a], r[o]
                s += chr(t[u] ^ r[(r[o] + r[a]) % 256])


Review comment (suggestion):
```suggestion
        parts = file_id.split('*')
        filename = ''.join(cgstr[int(part)] for part in parts if part.isdigit())
```

Code after:
                        'height': 180,
                    },
                ],
                'categories': ['人文'],
                'duration': 93,
                'view_count': int,
                'like_count': int,
            },
        },
        {
            # VIP-restricted audio
            'url': 'https://www.ximalaya.com/sound/562111701',
            'only_matching': True,
        },
    ]

    @staticmethod
    def _decrypt_filename(file_id, seed):
        cgstr = ''
        key = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\\:._-1234567890'
        for _ in key:
            seed = float(int(211 * seed + 30031) % 65536)
            r = int(seed / 65536 * len(key))
            cgstr += key[r]
            key = key.replace(key[r], '')
        parts = file_id.split('*')
        filename = ''.join(cgstr[int(part)] for part in parts if part.isdecimal())
        if not filename.startswith('/'):
            filename = '/' + filename
        return filename

    @staticmethod
    def _decrypt_url_params(encrypted_params):
        params = VideaIE.rc4(
            base64.b64decode(encrypted_params), 'xkt3a41psizxrh9l').split('-')
        # sign, token, timestamp
        return params[1], params[2], params[3]

    def _real_extract(self, url):
        scheme = 'https' if url.startswith('https') else 'http'

        audio_id = self._match_id(url)
        audio_info = self._download_json(
            f'{scheme}://m.ximalaya.com/tracks/{audio_id}.json', audio_id,
            'Downloading info json', 'Unable to download info file')

        formats = []
        # NOTE: VIP-restricted audio
        if audio_info.get('is_paid'):
            ts = int(time.time())
            vip_info = self._download_json(