mirror of
https://github.com/wbt5/real-url.git
synced 2025-06-17 08:25:25 +08:00
🐛 Fix 人人直播
-更新请求地址及正则匹配不到的问题 -优化代码
This commit is contained in:
parent
8dbe5981e2
commit
5131a8d5f6
36
renren.py
36
renren.py
@ -2,36 +2,28 @@
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
import hashlib
|
|
||||||
|
|
||||||
|
|
||||||
class RenRen:
|
class RenRen:
|
||||||
|
|
||||||
def __init__(self, rid):
|
def __init__(self, rid):
|
||||||
|
"""
|
||||||
|
直播间地址形式:http://activity.renren.com/live/liveroom/970302934_21348
|
||||||
|
rid即970302934_21348
|
||||||
|
Args:
|
||||||
|
rid:房间号
|
||||||
|
"""
|
||||||
self.rid = rid
|
self.rid = rid
|
||||||
|
self.s = requests.Session()
|
||||||
|
|
||||||
def get_real_url(self):
|
def get_real_url(self):
|
||||||
with requests.Session() as s:
|
res = self.s.get(f'http://activity.renren.com/live/liveroom/{self.rid}').text
|
||||||
res = s.get('http://activity.renren.com/liveroom/' + str(self.rid))
|
try:
|
||||||
livestate = re.search(r'"liveState":(\d)', res.text)
|
s = re.search(r'playUrl":"(.*?)"', res)
|
||||||
if livestate:
|
play_url = s.group(1)
|
||||||
try:
|
return play_url
|
||||||
s = re.search(r'"playUrl":"([\s\S]*?)"', res.text).group(1)
|
except Exception:
|
||||||
if livestate.group(1) == '0':
|
raise Exception('解析错误')
|
||||||
# accesskey = re.search(r'accesskey=(\w+)', s).group(1)
|
|
||||||
# expire = re.search(r'expire=(\d+)', s).group(1)
|
|
||||||
# live = re.search(r'(/live/\d+)', s).group(1)
|
|
||||||
# c = accesskey + expire + live
|
|
||||||
# key = hashlib.md5(c.encode('utf-8')).hexdigest()
|
|
||||||
# e = s.split('?')[0].split('/')[4]
|
|
||||||
# t = 'http://ksy-hls.renren.com/live/' + e + '/index.m3u8?key=' + key
|
|
||||||
return s
|
|
||||||
elif livestate.group(1) == '1':
|
|
||||||
return '回放:' + s
|
|
||||||
except IndexError:
|
|
||||||
raise Exception('解析错误')
|
|
||||||
else:
|
|
||||||
raise Exception('直播间不存在')
|
|
||||||
|
|
||||||
|
|
||||||
def get_real_url(rid):
|
def get_real_url(rid):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user