From d98f8e4031224e12b55a4a19b19f1681ab66ba60 Mon Sep 17 00:00:00 2001 From: Lucien Shui Date: Thu, 3 Jun 2021 23:47:33 +0800 Subject: [PATCH 1/5] Fix bilibili danmaku fetch --- danmu/danmaku/bilibili.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/danmu/danmaku/bilibili.py b/danmu/danmaku/bilibili.py index 93541b1..531bd40 100644 --- a/danmu/danmaku/bilibili.py +++ b/danmu/danmaku/bilibili.py @@ -76,12 +76,25 @@ class Bilibili: msg = {} if ops[i] == 5: j = json.loads(d) - msg['msg_type'] = {'SEND_GIFT': 'gift', 'DANMU_MSG': 'danmaku', - 'WELCOME': 'enter', 'NOTICE_MSG': 'broadcast'}.get(j.get('cmd'), 'other') + msg['msg_type'] = { + 'SEND_GIFT': 'gift', + 'DANMU_MSG': 'danmaku', + 'WELCOME': 'enter', + 'NOTICE_MSG': 'broadcast', + 'LIVE_INTERACTIVE_GAME': 'interactive_danmaku' # 新增互动弹幕,经测试与弹幕内容一致 + }.get(j.get('cmd'), 'other') + + # 2021-06-03 bilibili 字段更新, 形如 DANMU_MSG:4:0:2:2:2:0 + if msg.get('msg_type', 'UNKNOWN').startswith('DANMU_MSG'): + msg['msg_type'] = 'danmaku' + if msg['msg_type'] == 'danmaku': msg['name'] = (j.get('info', ['', '', ['', '']])[2][1] or j.get('data', {}).get('uname', '')) msg['content'] = j.get('info', ['', ''])[1] + elif msg['msg_type'] == 'interactive_danmaku': + msg['name'] = j.get('data', {}).get('uname', '') + msg['content'] = j.get('data', {}).get('msg', '') elif msg['msg_type'] == 'broadcast': msg['type'] = j.get('msg_type', 0) msg['roomid'] = j.get('real_roomid', 0) From 533ca8426877cda3f310e3506cc3a7e5ea148d58 Mon Sep 17 00:00:00 2001 From: BoneAsh Date: Mon, 28 Jun 2021 11:00:56 +0800 Subject: [PATCH 2/5] Fix huya --- huya.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/huya.py b/huya.py index 99635e1..afe9f20 100644 --- a/huya.py +++ b/huya.py @@ -23,7 +23,7 @@ class HuYa: '(KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36 ' } response = requests.get(url=room_url, headers=header).text - livelineurl = re.findall(r'liveLineUrl = "([\s\S]*?)";', response)[0] + livelineurl = re.findall(r'"liveLineUrl":"([\s\S]*?)"', response)[0] livelineurl = base64.b64decode(livelineurl).decode('utf-8') if livelineurl: if 'replay' in livelineurl: @@ -32,7 +32,7 @@ class HuYa: } else: stream_name = self.get_stream_name(livelineurl) - base_url = 'http://121.12.115.15/tx.hls.huya.com/src/' + stream_name + base_url = 'http://121.12.115.26/tx.hls.huya.com/src/' + stream_name real_url = { 'hls': base_url + '.m3u8', 'flv': base_url + '.flv', From 5e5b43d55c0df7e460e0bc359470975fda9b40ac Mon Sep 17 00:00:00 2001 From: bbll <768963019@QQ.com> Date: Fri, 2 Jul 2021 16:38:54 +0800 Subject: [PATCH 3/5] fix huya danmu --- danmu/danmaku/huya.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/danmu/danmaku/huya.py b/danmu/danmaku/huya.py index 9ee82df..e7fa746 100644 --- a/danmu/danmaku/huya.py +++ b/danmu/danmaku/huya.py @@ -22,11 +22,11 @@ class Huya: async with aiohttp.ClientSession() as session: async with session.get(url, headers=headers) as resp: room_page = await resp.text() - m = re.search(r"ayyuid: +'([0-9]+)'", room_page, re.MULTILINE) + m = re.search(r"lYyid\":([0-9]+)", room_page, re.MULTILINE) ayyuid = m.group(1) - m = re.search(r"TOPSID += +'([0-9]+)'", room_page, re.MULTILINE) + m = re.search(r"lChannelId\":([0-9]+)", room_page, re.MULTILINE) tid = m.group(1) - m = re.search(r"SUBSID += +'([0-9]+)'", room_page, re.MULTILINE) + m = re.search(r"lSubChannelId\":([0-9]+)", room_page, re.MULTILINE) sid = m.group(1) oos = tarscore.TarsOutputStream() From 74bfcfe483b2849995ae84b4e205ffc780e604fd Mon Sep 17 00:00:00 2001 From: BoneAsh Date: Sat, 3 Jul 2021 11:15:35 +0800 Subject: [PATCH 4/5] Fix huya --- huya.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/huya.py b/huya.py index afe9f20..9717900 100644 --- a/huya.py +++ b/huya.py @@ -32,11 +32,11 @@ class HuYa: } else: stream_name = self.get_stream_name(livelineurl) - base_url = 'http://121.12.115.26/tx.hls.huya.com/src/' + stream_name + base_url = 'http://121.12.115.29/tx.hls.huya.com/src/' + stream_name real_url = { - 'hls': base_url + '.m3u8', + # 'hls': base_url + '.m3u8', 'flv': base_url + '.flv', - 'hls_2m': base_url + '.m3u8?ratio=2000', + # 'hls_2m': base_url + '.m3u8?ratio=2000', 'flv_2m': base_url + '.flv?ratio=2000' } else: From e34d184d1913254a5508b9acb67f190acf0d6e46 Mon Sep 17 00:00:00 2001 From: BoneAsh Date: Sat, 3 Jul 2021 13:17:17 +0800 Subject: [PATCH 5/5] Fix huya --- huya.py | 61 ++++++++------------------------------------------------- 1 file changed, 8 insertions(+), 53 deletions(-) diff --git a/huya.py b/huya.py index 9717900..6c1a6f8 100644 --- a/huya.py +++ b/huya.py @@ -7,6 +7,7 @@ import base64 import urllib.parse import hashlib import time +import json class HuYa: @@ -23,63 +24,17 @@ class HuYa: '(KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36 ' } response = requests.get(url=room_url, headers=header).text - livelineurl = re.findall(r'"liveLineUrl":"([\s\S]*?)"', response)[0] - livelineurl = base64.b64decode(livelineurl).decode('utf-8') - if livelineurl: - if 'replay' in livelineurl: - real_url = { - 'replay': "https:" + livelineurl, - } - else: - stream_name = self.get_stream_name(livelineurl) - base_url = 'http://121.12.115.29/tx.hls.huya.com/src/' + stream_name - real_url = { - # 'hls': base_url + '.m3u8', - 'flv': base_url + '.flv', - # 'hls_2m': base_url + '.m3u8?ratio=2000', - 'flv_2m': base_url + '.flv?ratio=2000' - } - else: + streamInfo = json.loads(re.findall(r"", response)[0])["roomInfo"]["tLiveInfo"]["tLiveStreamInfo"]["vStreamInfo"]["value"] + if streamInfo == []: raise Exception('未开播或直播间不存在') + real_url = {} + for info in streamInfo: + real_url[info["sCdnType"].lower() + "_flv"] = info["sFlvUrl"] + "/" + info["sStreamName"] + "." + info["sFlvUrlSuffix"] + "?" + info["sFlvAntiCode"] + real_url[info["sCdnType"].lower() + "_hls"] = info["sHlsUrl"] + "/" + info["sStreamName"] + "." + info["sHlsUrlSuffix"] + "?" + info["sHlsAntiCode"] except Exception as e: raise Exception('未开播或直播间不存在') return real_url - @staticmethod - def get_stream_name(e): - i, b = e.split('?') - r = i.split('/') - s = re.sub(r'.(flv|m3u8)', '', r[-1]) - return s - - @staticmethod - def live(e): - i, b = e.split('?') - r = i.split('/') - s = re.sub(r'.(flv|m3u8)', '', r[-1]) - c = b.split('&') - c = [i for i in c if i != ''] - n = {i.split('=')[0]: i.split('=')[1] for i in c} - fm = urllib.parse.unquote(n['fm']) - u = base64.b64decode(fm).decode('utf-8') - p = u.split('_')[0] - seqid = str(int(time.time() * 1e7)) - ctype = n['ctype'] - t = n['t'] - mf = hashlib.md5((seqid + '|' + ctype + '|' + t).encode('utf-8')).hexdigest() - ll = n['wsTime'] - ratio = n.get('ratio') - if ratio is None: - ratio = '' - uid = '1279523789849' - h = '_'.join([p, uid, s, mf, ll]) - m = hashlib.md5(h.encode('utf-8')).hexdigest() - txyp = n['txyp'] - fs = n['fs'] - url = "{}?wsSecret={}&wsTime={}&uuid=&uid={}&seqid={}&ratio={}&txyp={}&fs={}&ctype={}&ver=1&t={}".format( - i, m, ll, uid, seqid, ratio, txyp, fs, ctype, t) - return url - def get_real_url(rid): try: @@ -92,4 +47,4 @@ def get_real_url(rid): if __name__ == '__main__': rid = input('输入虎牙直播房间号:\n') - print(get_real_url(rid)) + print(get_real_url(rid)) \ No newline at end of file