mirror of
https://github.com/wbt5/real-url.git
synced 2025-08-02 23:55:46 +08:00
更新哔哩哔哩直播
This commit is contained in:
parent
dbb54c8e89
commit
3f0c3c6abe
91
bilibili.py
91
bilibili.py
@ -1,61 +1,50 @@
|
|||||||
# 获取哔哩哔哩直播的真实流媒体地址。
|
# 获取哔哩哔哩直播的真实流媒体地址,默认获取直播间提供的最高画质
|
||||||
# PC网页和手机APP端的qn=1是最高画质;qn取值0~4。
|
# qn=150高清
|
||||||
# 手机网页端的只找到一个值qn=0。
|
# qn=250超清
|
||||||
|
# qn=400蓝光
|
||||||
|
# qn=10000原画
|
||||||
import requests
|
import requests
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
def get_real_rid(rid):
|
def bilibili(rid):
|
||||||
room_url = 'https://api.live.bilibili.com/room/v1/Room/room_init?id=' + str(rid)
|
# 先获取直播状态和真实房间号
|
||||||
response = requests.get(url=room_url).json()
|
r_url = 'https://api.live.bilibili.com/room/v1/Room/room_init?id={}'.format(rid)
|
||||||
data = response.get('data', 0)
|
with requests.Session() as s:
|
||||||
if data:
|
res = s.get(r_url).json()
|
||||||
live_status = data.get('live_status', 0)
|
code = res['code']
|
||||||
room_id = data.get('room_id', 0)
|
if code == 0:
|
||||||
else:
|
live_status = res['data']['live_status']
|
||||||
live_status = room_id = 0
|
if live_status == 1:
|
||||||
return live_status, room_id
|
room_id = res['data']['room_id']
|
||||||
|
|
||||||
|
def u(pf):
|
||||||
def get_real_url_flv(rid):
|
f_url = 'https://api.live.bilibili.com/xlive/web-room/v1/playUrl/playUrl'
|
||||||
room = get_real_rid(rid)
|
params = {
|
||||||
live_status = room[0]
|
'cid': room_id,
|
||||||
room_id = room[1]
|
'qn': 10000,
|
||||||
qn = 1 # PC网页和手机APP端的qn=1是最高画质;qn取值0~4。
|
'platform': pf,
|
||||||
if live_status:
|
'https_url_req': 1,
|
||||||
|
'ptype': 16
|
||||||
|
}
|
||||||
|
resp = s.get(f_url, params=params).json()
|
||||||
try:
|
try:
|
||||||
room_url = 'https://api.live.bilibili.com/xlive/web-room/v1/index/getRoomPlayInfo?room_id={}&play_url=1&mask=1&qn={}&platform=web'.format(room_id, qn)
|
durl = resp['data']['durl']
|
||||||
response = requests.get(url=room_url).json()
|
real_url = durl[-1]['url']
|
||||||
durl = response.get('data').get('play_url').get('durl', 0)
|
|
||||||
real_url = durl[-1].get('url')
|
|
||||||
except:
|
|
||||||
real_url = '疑似部分国外IP无法GET到正确数据,待验证'
|
|
||||||
else:
|
|
||||||
real_url = '未开播或直播间不存在'
|
|
||||||
return real_url
|
return real_url
|
||||||
|
except KeyError or IndexError:
|
||||||
|
raise Exception('获取失败')
|
||||||
|
|
||||||
|
return {
|
||||||
|
'flv_url': u('web'),
|
||||||
|
'hls_url': u('h5')
|
||||||
|
}
|
||||||
|
|
||||||
def get_real_url_hls(rid):
|
|
||||||
room = get_real_rid(rid)
|
|
||||||
live_status = room[0]
|
|
||||||
room_id = room[1]
|
|
||||||
qn = 0 # 手机网页端的只找到一个值qn=0。
|
|
||||||
if live_status:
|
|
||||||
try:
|
|
||||||
room_url = 'https://api.live.bilibili.com/xlive/web-room/v1/playUrl/playUrl?cid={}&platform=h5&otype=json&quality={}'.format(room_id, qn)
|
|
||||||
response = requests.get(url=room_url).json()
|
|
||||||
durl = response.get('data').get('durl', 0)
|
|
||||||
real_url = durl[-1].get('url')
|
|
||||||
except:
|
|
||||||
real_url = '疑似部分国外IP无法GET到正确数据,待验证'
|
|
||||||
else:
|
else:
|
||||||
real_url = '未开播或直播间不存在'
|
raise Exception('未开播')
|
||||||
return real_url
|
else:
|
||||||
|
raise Exception('房间不存在')
|
||||||
|
|
||||||
rid = input('请输入bilibili房间号:\n')
|
|
||||||
real_url_flv = get_real_url_flv(rid)
|
if __name__ == '__main__':
|
||||||
# real_url_hls = get_real_url_hls(rid)
|
r = input('输入bilibili直播间号:\n')
|
||||||
print('该直播间源地址为:')
|
print(bilibili(r))
|
||||||
print(real_url_flv)
|
|
||||||
# print(real_url_hls)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user