Skip to content

Commit 5131a8d

Browse files
committed
🐛 Fix 人人直播
-更新请求地址及正则匹配不到的问题 -优化代码
1 parent 8dbe598 commit 5131a8d

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

renren.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,28 @@
22

33
import requests
44
import re
5-
import hashlib
65

76

87
class RenRen:
98

109
def __init__(self, rid):
10+
"""
11+
直播间地址形式:http://activity.renren.com/live/liveroom/970302934_21348
12+
rid即970302934_21348
13+
Args:
14+
rid:房间号
15+
"""
1116
self.rid = rid
17+
self.s = requests.Session()
1218

1319
def get_real_url(self):
14-
with requests.Session() as s:
15-
res = s.get('http://activity.renren.com/liveroom/' + str(self.rid))
16-
livestate = re.search(r'"liveState":(\d)', res.text)
17-
if livestate:
18-
try:
19-
s = re.search(r'"playUrl":"([\s\S]*?)"', res.text).group(1)
20-
if livestate.group(1) == '0':
21-
# accesskey = re.search(r'accesskey=(\w+)', s).group(1)
22-
# expire = re.search(r'expire=(\d+)', s).group(1)
23-
# live = re.search(r'(/live/\d+)', s).group(1)
24-
# c = accesskey + expire + live
25-
# key = hashlib.md5(c.encode('utf-8')).hexdigest()
26-
# e = s.split('?')[0].split('/')[4]
27-
# t = 'http://ksy-hls.renren.com/live/' + e + '/index.m3u8?key=' + key
28-
return s
29-
elif livestate.group(1) == '1':
30-
return '回放:' + s
31-
except IndexError:
32-
raise Exception('解析错误')
33-
else:
34-
raise Exception('直播间不存在')
20+
res = self.s.get(f'http://activity.renren.com/live/liveroom/{self.rid}').text
21+
try:
22+
s = re.search(r'playUrl":"(.*?)"', res)
23+
play_url = s.group(1)
24+
return play_url
25+
except Exception:
26+
raise Exception('解析错误')
3527

3628

3729
def get_real_url(rid):

0 commit comments

Comments
 (0)