1 Star 0 Fork 0

果冻/real-url

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
renren.py 1.51 KB
一键复制 编辑 原始数据 按行查看 历史
wbt5 提交于 2020-12-20 15:20 . fixed
# 人人直播:http://zhibo.renren.com/
import requests
import re
import hashlib
class RenRen:
def __init__(self, rid):
self.rid = rid
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('直播间不存在')
def get_real_url(rid):
try:
rr = RenRen(rid)
return rr.get_real_url()
except Exception as e:
print('Exception:', e)
return False
if __name__ == '__main__':
r = input('请输入人人直播房间号:\n')
print(get_real_url(r))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jelly27/real-url.git
git@gitee.com:jelly27/real-url.git
jelly27
real-url
real-url
master

搜索帮助