1
0
mirror of https://github.com/wbt5/real-url.git synced 2025-08-13 23:31:38 +08:00

Compare commits

..

No commits in common. "7b40185347b849d0a920c838eec2d2da09d90a11" and "52329a5db7172f14f37287201b666d41b77dafd7" have entirely different histories.

31
huya.py
View File

@ -24,32 +24,15 @@ 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
info = json.loads(re.findall(r"<script> window.HNF_GLOBAL_INIT = (.*)</script>", response)[0]) streamInfo = json.loads(re.findall(r"<script> window.HNF_GLOBAL_INIT = (.*)</script>", response)[0])["roomInfo"]["tLiveInfo"]["tLiveStreamInfo"]["vStreamInfo"]["value"]
if info == {'exceptionType': 0}: if streamInfo == []:
raise Exception('房间不存在') raise Exception('未开播或直播间不存在')
roomInfo = info["roomInfo"]
real_url = {} real_url = {}
for info in streamInfo:
# not live real_url[info["sCdnType"].lower() + "_flv"] = info["sFlvUrl"] + "/" + info["sStreamName"] + "." + info["sFlvUrlSuffix"] + "?" + info["sFlvAntiCode"]
if roomInfo["eLiveStatus"] == 1: real_url[info["sCdnType"].lower() + "_hls"] = info["sHlsUrl"] + "/" + info["sStreamName"] + "." + info["sHlsUrlSuffix"] + "?" + info["sHlsAntiCode"]
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(e) raise Exception('未开播或直播间不存在')
return real_url return real_url