1
0
mirror of https://github.com/wbt5/real-url.git synced 2025-07-28 12:15:52 +08:00

Add huya replay

This commit is contained in:
BoneAsh 2021-07-28 09:58:19 +08:00
parent 52329a5db7
commit 8b5364256e

31
huya.py
View File

@ -24,15 +24,32 @@ class HuYa:
'(KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36 ' '(KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36 '
} }
response = requests.get(url=room_url, headers=header).text response = requests.get(url=room_url, headers=header).text
streamInfo = json.loads(re.findall(r"<script> window.HNF_GLOBAL_INIT = (.*)</script>", response)[0])["roomInfo"]["tLiveInfo"]["tLiveStreamInfo"]["vStreamInfo"]["value"] info = json.loads(re.findall(r"<script> window.HNF_GLOBAL_INIT = (.*)</script>", response)[0])
if streamInfo == []: if info == {'exceptionType': 0}:
raise Exception('未开播或直播间不存在') raise Exception('房间不存在')
roomInfo = info["roomInfo"]
real_url = {} real_url = {}
for info in streamInfo:
real_url[info["sCdnType"].lower() + "_flv"] = info["sFlvUrl"] + "/" + info["sStreamName"] + "." + info["sFlvUrlSuffix"] + "?" + info["sFlvAntiCode"] # not live
real_url[info["sCdnType"].lower() + "_hls"] = info["sHlsUrl"] + "/" + info["sStreamName"] + "." + info["sHlsUrlSuffix"] + "?" + info["sHlsAntiCode"] if roomInfo["eLiveStatus"] == 1:
raise Exception('未开播')
# live
elif roomInfo["eLiveStatus"] == 2:
streamInfos = roomInfo["tLiveInfo"]["tLiveStreamInfo"]["vStreamInfo"]["value"]
for streamInfo in streamInfos:
real_url[streamInfo["sCdnType"].lower() + "_flv"] = streamInfo["sFlvUrl"] + "/" + streamInfo["sStreamName"] + "." + \
streamInfo["sFlvUrlSuffix"] + "?" + streamInfo["sFlvAntiCode"]
real_url[streamInfo["sCdnType"].lower() + "_hls"] = streamInfo["sHlsUrl"] + "/" + streamInfo["sStreamName"] + "." + \
streamInfo["sHlsUrlSuffix"] + "?" + streamInfo["sHlsAntiCode"]
# replay
elif roomInfo["eLiveStatus"] == 3:
real_url["replay"] = roomInfo["tReplayInfo"]["tReplayVideoInfo"]["sUrl"]
else:
raise Exception('未知错误')
except Exception as e: except Exception as e:
raise Exception('未开播或直播间不存在') raise Exception(e)
return real_url return real_url