forked from wbt5/real-url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yizhibo.py
41 lines (32 loc) · 967 Bytes
/
yizhibo.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
# 获取一直播的真实流媒体地址。
import requests
import re
class YiZhiBo:
def __init__(self, rid):
"""
一直播需要传入直播间的完整地址
Args:
rid:完整地址
"""
self.rid = rid
self.s = requests.Session()
def get_real_url(self):
try:
res = self.s.get(self.rid).text
play_url, status_code = re.findall(r'play_url:"(.*?)"[\s\S]*status:(\d+),', res)[0]
if status_code == '10':
return play_url
else:
raise Exception('未开播')
except Exception:
raise Exception('获取错误')
def get_real_url(rid):
try:
yzb = YiZhiBo(rid)
return yzb.get_real_url()
except Exception as e:
print('Exception:', e)
return False
if __name__ == '__main__':
r = input('请输入一直播房间地址:\n')
print(get_real_url(r))