1
0
mirror of https://github.com/wbt5/real-url.git synced 2025-06-16 15:59:57 +08:00

🐛 Fix 人人直播

-更新请求地址及正则匹配不到的问题
-优化代码
This commit is contained in:
wbt5 2021-11-21 01:35:19 +08:00
parent 8dbe5981e2
commit 5131a8d5f6
No known key found for this signature in database
GPG Key ID: 92D5C42E815A2BD6

View File

@ -2,36 +2,28 @@
import requests
import re
import hashlib
class RenRen:
def __init__(self, rid):
"""
直播间地址形式http://activity.renren.com/live/liveroom/970302934_21348
rid即970302934_21348
Args:
rid:房间号
"""
self.rid = rid
self.s = requests.Session()
def get_real_url(self):
with requests.Session() as s:
res = s.get('http://activity.renren.com/liveroom/' + str(self.rid))
livestate = re.search(r'"liveState":(\d)', res.text)
if livestate:
try:
s = re.search(r'"playUrl":"([\s\S]*?)"', res.text).group(1)
if livestate.group(1) == '0':
# 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('直播间不存在')
res = self.s.get(f'http://activity.renren.com/live/liveroom/{self.rid}').text
try:
s = re.search(r'playUrl":"(.*?)"', res)
play_url = s.group(1)
return play_url
except Exception:
raise Exception('解析错误')
def get_real_url(rid):