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

56 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 获取企鹅电竞的真实流媒体地址。
# 默认画质为超清
import requests
import re
class EGame:
def __init__(self, rid):
self.rid = rid
def get_real_url(self):
room_url = 'https://share.egame.qq.com/cgi-bin/pgg_async_fcgi'
post_data = {
'param': '''{"0":{"module":"pgg_live_read_svr","method":"get_live_and_profile_info","param":{"anchor_id":'''
+ str(self.rid) + ''',"layout_id":"hot","index":1,"other_uid":0}}}'''
}
try:
response = requests.post(url=room_url, data=post_data).json()
data = response.get('data', 0)
if data:
video_info = data.get('0').get(
'retBody').get('data').get('video_info')
pid = video_info.get('pid', 0)
if pid:
is_live = data.get('0').get(
'retBody').get('data').get('profile_info').get('is_live', 0)
if is_live:
play_url = video_info.get('stream_infos')[
0].get('play_url')
real_url = re.findall(r'([\w\W]+?)&uid=', play_url)[0]
else:
raise Exception('直播间未开播')
else:
raise Exception('直播间未启用')
else:
raise Exception('直播间不存在')
except:
raise Exception('数据请求错误')
return real_url
def get_real_url(rid):
try:
eg = EGame(rid)
return eg.get_real_url()
except Exception as e:
print('Exception', e)
return False
if __name__ == '__main__':
r = input('请输入企鹅电竞房间号:\n')
print(get_real_url(r))