mirror of
https://github.com/wbt5/real-url.git
synced 2025-07-27 11:00:32 +08:00
🐛修复虎牙一起看
This commit is contained in:
commit
cab036f982
86
huya.py
86
huya.py
@ -1,5 +1,4 @@
|
|||||||
# 获取虎牙直播的真实流媒体地址。
|
# 获取虎牙直播的真实流媒体地址。
|
||||||
# 虎牙"一起看"频道的直播间可能会卡顿,尝试将返回地址 tx.hls.huya.com 中的 tx 改为 bd、migu-bd。
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
@ -7,61 +6,52 @@ import base64
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
import hashlib
|
import hashlib
|
||||||
import time
|
import time
|
||||||
import json
|
|
||||||
|
def live(e):
|
||||||
|
i, b = e.split('?')
|
||||||
|
r = i.split('/')
|
||||||
|
s = re.sub(r'.(flv|m3u8)', '', r[-1])
|
||||||
|
c = b.split('&', 3)
|
||||||
|
c = [i for i in c if i != '']
|
||||||
|
n = {i.split('=')[0]: i.split('=')[1] for i in c}
|
||||||
|
fm = urllib.parse.unquote(n['fm'])
|
||||||
|
u = base64.b64decode(fm).decode('utf-8')
|
||||||
|
p = u.split('_')[0]
|
||||||
|
f = str(int(time.time() * 1e7))
|
||||||
|
l = n['wsTime']
|
||||||
|
t = '0'
|
||||||
|
h = '_'.join([p, t, s, f, l])
|
||||||
|
m = hashlib.md5(h.encode('utf-8')).hexdigest()
|
||||||
|
y = c[-1]
|
||||||
|
url = "{}?wsSecret={}&wsTime={}&u={}&seqid={}&{}".format(i, m, l, t, f, y)
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
class HuYa:
|
def get_real_url(room_id):
|
||||||
|
|
||||||
def __init__(self, rid):
|
|
||||||
self.rid = rid
|
|
||||||
|
|
||||||
def get_real_url(self):
|
|
||||||
try:
|
try:
|
||||||
room_url = 'https://m.huya.com/' + str(self.rid)
|
room_url = 'https://m.huya.com/' + str(room_id)
|
||||||
header = {
|
header = {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 '
|
'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||||
'(KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36 '
|
'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])
|
liveLineUrl = re.findall(r'"liveLineUrl":"([\s\S]*?)",', response)[0]
|
||||||
if info == {'exceptionType': 0}:
|
liveline = base64.b64decode(liveLineUrl).decode('utf-8')
|
||||||
raise Exception('房间不存在')
|
if liveline:
|
||||||
roomInfo = info["roomInfo"]
|
if 'replay' in liveline:
|
||||||
real_url = {}
|
return '直播录像:' + liveline
|
||||||
|
|
||||||
# not live
|
|
||||||
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:
|
else:
|
||||||
raise Exception('未知错误')
|
liveline = live(liveline)
|
||||||
except Exception as e:
|
real_url = ("https:" + liveline).replace("hls", "flv").replace("m3u8", "flv")
|
||||||
raise Exception(e)
|
else:
|
||||||
|
real_url = '未开播或直播间不存在'
|
||||||
|
except:
|
||||||
|
real_url = '未开播或直播间不存在'
|
||||||
return real_url
|
return real_url
|
||||||
|
|
||||||
|
|
||||||
def get_real_url(rid):
|
rid = input('输入虎牙直播房间号:\n')
|
||||||
try:
|
real_url = get_real_url(rid)
|
||||||
hy = HuYa(rid)
|
print('该直播间源地址为:')
|
||||||
return hy.get_real_url()
|
print(real_url)
|
||||||
except Exception as e:
|
|
||||||
print('Exception:', e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
rid = input('输入虎牙直播房间号:\n')
|
|
||||||
print(get_real_url(rid))
|
|
Loading…
x
Reference in New Issue
Block a user