forked from wbt5/real-url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lehai.py
54 lines (45 loc) · 1.6 KB
/
lehai.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
# 乐嗨直播:https://www.lehaitv.com/
from urllib.parse import urlencode
from urllib.parse import unquote
import requests
import time
import hashlib
class LeHai:
def __init__(self, rid):
self.rid = rid
def get_real_url(self):
url = f'https://service.lehaitv.com/v2/room/{self.rid}/media/advanceInfoRoom'
params = {
'_st1': int(time.time() * 1e3),
'accessToken': 's7FUbTJ+jILrR7kicJUg8qr025ZVjd07DAnUQd8c7g/o4OH9pdSX6w==',
'tku': 3000006,
}
data = urlencode(params) '1eha12h5'
_ajaxData1 = hashlib.md5(data.encode('utf-8')).hexdigest()
params['_ajaxData1'] = _ajaxData1
params['accessToken'] = unquote(params['accessToken'])
with requests.Session() as s:
res = s.get(url, params=params)
if res.status_code == 200:
res = res.json()
statuscode = res['status']['statuscode']
if statuscode == '0':
if res['data']['live_status'] == 1:
real_url = res['data']['medial_url_app_for_h264']
return real_url
else:
raise Exception('未开播')
else:
raise Exception('房间不存在 或 权限检查错误')
else:
raise Exception('请求错误')
def get_real_url(rid):
try:
lh = LeHai(rid)
return lh.get_real_url()
except Exception as e:
print('Exception:', e)
return False
if __name__ == '__main__':
r = input('输入乐嗨直播房间号:\n')
print(get_real_url(r))