diff --git a/app/ui/plugins/huya.tsx b/app/ui/plugins/huya.tsx index 4bc5c71..c0c0efe 100644 --- a/app/ui/plugins/huya.tsx +++ b/app/ui/plugins/huya.tsx @@ -120,8 +120,18 @@ const Huya: React.FC = props => { /> + int: + try: + if isinstance(uid, str): + uid = int(uid) + except ValueError: + pass + return uid or random.randint(1400000000000, 1499999999999) + + async def get_anonymous_uid(self) -> int: try: rsp = await client.post( @@ -332,21 +348,44 @@ class Huya(DownloadBase): "data": {}, } ) - data = json_loads(rsp.text) + rsp = json_loads(rsp.text) except: - return random.randint(1400000000000, 1499999999999) - else: - return data['data']['uid'] + rsp = {} + return rsp.get('data', {}).get('uid', self.get_uid()) @staticmethod - def update_user_agent(headers: dict): - # copied from stream-rec commit b48c9cd - valid_ts = 20000308 - current_ts = int(time.time()) - version = str(current_ts)[-8:] - version = version if int(version) > valid_ts else (valid_ts + (current_ts / 100)) - headers['user-agent'] = f"HYSDK(Windows, {version})" + def get_hyapp_ua() -> str: + hyapp_platform = 'huya_nftv' # adr or huya_nftv, pc_exe, webh5 + hyapp_version = '2.5.1.3141' # adr/nftv: LocalVersion or "0.0.0" + hotfix_version, pc_exe: 6070100, ws: 2505091506 + hyapp_channel = 'official' # adr: live, nftv/pc_exe: official, websocket + android_api_level = random.randint(28, 35) # Build.VERSION.SDK_INT + ua = f"{hyapp_platform}&{hyapp_version}&{hyapp_channel}" + return ua if hyapp_platform in {'pc_exe', 'webh5'} else f"{ua}&{android_api_level}" + + @staticmethod + def get_hysdk_ua() -> str: + hysdk_platform = 'Android' # Android, Windows + hysdk_version = '30000002' # 30000002 + return f"HYSDK({hysdk_platform}, {hysdk_version})" + + @staticmethod + def get_hy_media_player_ua() -> str: + hy_mp_platform = 'android' # android + hy_mp_version = '20000313' # 20000313 + return f"{hy_mp_platform}, {hy_mp_version}" + + @staticmethod + def get_hy_trans_mod_ua() -> str: + hy_trans_mod_name = 'trans' # trans + hy_trans_mod_version = '1.24.99-rel-tv' # nftv: 1.24.99-rel-tv, adr: 2.22.13-rel, win: 2.21.0.4784 + return f"{hy_trans_mod_name}&{hy_trans_mod_version}" + + @staticmethod + def update_headers(headers: dict): + user_agent = f"{Huya.get_hy_media_player_ua()}_APP({Huya.get_hyapp_ua()})_SDK({Huya.get_hy_trans_mod_ua()})" + # user_agent = f"{Huya.get_hysdk_ua()}_APP({Huya.get_hyapp_ua()})_SDK({Huya.get_hy_trans_mod_ua()})" + headers['user-agent'] = user_agent headers['origin'] = HUYA_WEB_BASE_URL