forked from wbt5/real-url
-
Notifications
You must be signed in to change notification settings - Fork 1
/
huomao.py
76 lines (64 loc) · 2.62 KB
/
huomao.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 获取火猫直播的真实流媒体地址,默认为最高画质.
# 获取的流媒体地址如:http://live-lx-hdl.huomaotv.cn/live/qvCESZ?t=1573928152&r=377789475848&stream=qvCESZ&rid=oubvc2y3v&token=44a7f115f0af496e268bcbb7cdbb63b1&url=http%3A%2F%2Flive-lx-hdl.huomaotv.cn%2Flive%2FqvCESZ&from=huomaoh5room
# 实际上使用http://live-lx-hdl.huomaotv.cn/live/qvCESZ?token=44a7f115f0af496e268bcbb7cdbb63b1,即可播放
# 链接中lx可替换cdn(lx,tx,ws,js,jd2等),媒体类型可为.flv或.m3u8,码率可为BL8M,BL4M,TD,BD,HD,SD
import requests
import time
import hashlib
import re
class HuoMao:
def __init__(self, rid):
self.rid = rid
@staticmethod
def get_time():
tt = str(int((time.time() * 1000)))
return tt
@staticmethod
def get_videoids(rid):
room_url = 'https://www.huomao.com/mobile/mob_live/' + str(rid)
response = requests.get(url=room_url).text
try:
videoids = re.findall(r'var stream = "([\w\W]+?)";', response)[0]
except:
videoids = 0
return videoids
@staticmethod
def get_token(videoids, time):
token = hashlib.md5((str(videoids) + 'huomaoh5room' + str(time) +
'6FE26D855E1AEAE090E243EB1AF73685').encode('utf-8')).hexdigest()
return token
def get_real_url(self):
videoids = self.get_videoids(self.rid)
if videoids:
time = self.get_time()
token = self.get_token(videoids, time)
room_url = 'https://www.huomao.com/swf/live_data'
post_data = {
'cdns': 1,
'streamtype': 'live',
'VideoIDS': videoids,
'from': 'huomaoh5room',
'time': time,
'token': token
}
response = requests.post(url=room_url, data=post_data).json()
roomStatus = response.get('roomStatus', 0)
if roomStatus == '1':
real_url_flv = response.get('streamList')[-1].get('list')[0].get('url')
real_url_m3u8 = response.get('streamList')[-1].get('list_hls')[0].get('url')
real_url = [real_url_flv, real_url_m3u8.replace('_480', '')]
else:
raise Exception('直播间未开播')
else:
raise Exception('直播间不存在')
return real_url
def get_real_url(rid):
try:
hm = HuoMao(rid)
return hm.get_real_url()
except Exception as e:
print('Exception:', e)
return False
if __name__ == '__main__':
r = input('请输入火猫直播房间号:\n')
print(get_real_url(r))