forked from wbt5/real-url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xunlei.py
56 lines (47 loc) · 1.47 KB
/
xunlei.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 迅雷直播:https://live.xunlei.com/global/index.html?id=0
import requests
import hashlib
import time
from urllib.parse import urlencode
class XunLei:
def __init__(self, rid):
self.rid = rid
def get_real_url(self):
url = 'https://biz-live-ssl.xunlei.com//caller'
headers = {
'cookie': 'appid=1002'
}
_t = int(time.time() * 1000)
u = '1002'
f = '&*%$7987321GKwq'
params = {
'_t': _t,
'a': 'play',
'c': 'room',
'hid': 'h5-e70560ea31cc17099395c15595bdcaa1',
'uuid': self.rid,
}
data = urlencode(params)
p = hashlib.md5(f'{u}{data}{f}'.encode('utf-8')).hexdigest()
params['sign'] = p
with requests.Session() as s:
res = s.get(url, params=params, headers=headers).json()
if res['result'] == 0:
play_status = res['data']['play_status']
if play_status == 1:
real_url = res['data']['data']['stream_pull_https']
return real_url
else:
raise Exception('未开播')
else:
raise Exception('直播间可能不存在')
def get_real_url(rid):
try:
xl = XunLei(rid)
return xl.get_real_url()
except Exception as e:
print('Exception:', e)
return False
if __name__ == '__main__':
r = input('请输入迅雷直播房间号:\n')
print(get_real_url(r))