1
0
mirror of https://github.com/wbt5/real-url.git synced 2025-08-01 14:48:01 +08:00

🐛 Fix 酷我聚星直播

-更新请求地址
-完善VIP房间号的获取
-完善竖屏直播间的获取
-优化代码
This commit is contained in:
wbt5 2021-11-13 21:56:49 +08:00
parent e6bfbb58e2
commit a3865d88c7
No known key found for this signature in database
GPG Key ID: 92D5C42E815A2BD6

41
kuwo.py
View File

@ -1,26 +1,44 @@
# 酷我聚星直播http://jx.kuwo.cn/
import requests
import re
class KuWo:
def __init__(self, rid):
self.rid = rid
self.BASE_URL = 'https://jxm0.kuwo.cn/video/mo/live/pull/h5/v3/streamaddr'
self.s = requests.Session()
def get_real_url(self):
with requests.Session() as s:
res = s.get('https://zhiboserver.kuwo.cn/proxy.p?src=h5&cmd=enterroom&rid={}&videotype=1&auto=1'.format(self.rid))
res = res.json()
try:
livestatus = res['room']['livestatus']
except KeyError:
raise Exception('房间号错误')
if livestatus == 2:
real_url = res['live']['url']
return real_url
res = self.s.get(f'https://jx.kuwo.cn/{self.rid}').text
roomid = re.search(r"roomId: '(\d*)'", res)
if roomid:
self.rid = roomid.group(1)
else:
raise Exception('未开播')
raise Exception('未开播或房间号错误')
params = {
'std_bid': 1,
'roomId': self.rid,
'platform': 405,
'version': 1000,
'streamType': '3-6',
'liveType': 1,
'ch': 'fx',
'ua': 'fx-mobile-h5',
'kugouId': 0,
'layout': 1,
'videoAppId': 10011,
}
res = self.s.get(self.BASE_URL, params=params).json()
if res['data']['sid'] == -1:
raise Exception('未开播或房间号错误')
try:
url = res['data']['horizontal'][0]['httpshls'][0]
except (KeyError, IndexError):
url = res['data']['vertical'][0]['httpshls'][0]
return url
def get_real_url(rid):
@ -35,4 +53,3 @@ def get_real_url(rid):
if __name__ == '__main__':
r = input('输入酷我聚星直播房间号:\n')
print(get_real_url(r))