From e4e1e94a872f439aaf6cae810579bda34b07ad09 Mon Sep 17 00:00:00 2001 From: wbt5 Date: Sat, 7 Dec 2019 01:14:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=93=94=E5=93=A9=E5=93=94?= =?UTF-8?q?=E5=93=A9=E7=9B=B4=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bilibili.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/bilibili.py b/bilibili.py index bed235b..e904c01 100644 --- a/bilibili.py +++ b/bilibili.py @@ -23,15 +23,12 @@ def get_real_url(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() - durl = response.get('data').get('durl', 0) - if durl: - result = 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: + try: + room_url = 'https://api.live.bilibili.com/xlive/web-room/v1/index/getRoomPlayInfo?room_id={}&play_url=1&mask=1&qn=0&platform=web'.format(room_id) + response = requests.get(url=room_url).json() + durl = response.get('data').get('play_url').get('durl', 0) + real_url = durl[-1].get('url') + except: real_url = '疑似部分国外IP无法GET到正确数据,待验证' else: real_url = '未开播或直播间不存在'