mirror of
https://github.com/wbt5/real-url.git
synced 2025-07-27 11:00:32 +08:00
新增哔哩哔哩直播源
This commit is contained in:
parent
57badc229b
commit
c20e25b22f
35
get_bilibili_real_url.py
Normal file
35
get_bilibili_real_url.py
Normal file
@ -0,0 +1,35 @@
|
||||
# 获取哔哩哔哩直播的真实流媒体地址。
|
||||
# quality=4默认画质为原画
|
||||
|
||||
|
||||
import requests
|
||||
import re
|
||||
|
||||
|
||||
def get_real_rid(rid):
|
||||
room_url = 'https://api.live.bilibili.com/room/v1/Room/room_init?id=' + str(rid)
|
||||
response = requests.get(url=room_url).json()
|
||||
live_status = response.get('data').get('live_status')
|
||||
room_id = response.get('data').get('room_id')
|
||||
return live_status, room_id
|
||||
|
||||
|
||||
def get_real_url(rid):
|
||||
room = get_real_rid(rid)
|
||||
live_status = room[0]
|
||||
room_id = room[1]
|
||||
if live_status:
|
||||
room_url = 'https://api.live.bilibili.com/room/v1/Room/playUrl?cid=' +str(room_id) + '&platform=h5&otype=json&quality=4'
|
||||
response = requests.get(url=room_url).json()
|
||||
result = response.get('data').get('durl')[0].get('url')
|
||||
pattern = r'.com/live-[\S]*/([\s\S]*.m3u8)'
|
||||
pattern_result = re.findall(pattern, result, re.I)[0]
|
||||
real_url = 'https://cn-hbxy-cmcc-live-01.live-play.acgvideo.com/live-bvc/' + pattern_result
|
||||
else:
|
||||
real_url = '未开播或直播间不存在'
|
||||
return real_url
|
||||
|
||||
|
||||
rid = input('请输入bilibili房间号:\n')
|
||||
real_url = get_real_url(rid)
|
||||
print('该直播间源地址为:\n' + real_url)
|
Loading…
x
Reference in New Issue
Block a user