File tree Expand file tree Collapse file tree 1 file changed +14
-22
lines changed Expand file tree Collapse file tree 1 file changed +14
-22
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import requests
4
4
import re
5
- import hashlib
6
5
7
6
8
7
class RenRen :
9
8
10
9
def __init__ (self , rid ):
10
+ """
11
+ 直播间地址形式:http://activity.renren.com/live/liveroom/970302934_21348
12
+ rid即970302934_21348
13
+ Args:
14
+ rid:房间号
15
+ """
11
16
self .rid = rid
17
+ self .s = requests .Session ()
12
18
13
19
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 ('解析错误' )
35
27
36
28
37
29
def get_real_url (rid ):
You can’t perform that action at this time.
0 commit comments