From 1380bf2312bb4e7c98acdb730fadc366f8f1f612 Mon Sep 17 00:00:00 2001 From: RAiN Date: Wed, 16 Jun 2021 23:55:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E4=BA=8Edingzhengjie=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E7=9A=84=E6=96=B9=E6=B3=95=E6=9D=A5=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E8=99=8E=E7=89=99=E7=9B=B4=E6=92=AD=E5=9C=B0=E5=9D=80=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- huya.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/huya.py b/huya.py index 9a8ce6a..99635e1 100644 --- a/huya.py +++ b/huya.py @@ -31,13 +31,13 @@ class HuYa: 'replay': "https:" + livelineurl, } else: - s_url = self.live(livelineurl) - b_url = self.live(livelineurl.replace('_2000', '')) + stream_name = self.get_stream_name(livelineurl) + base_url = 'http://121.12.115.15/tx.hls.huya.com/src/' + stream_name real_url = { - '2000p': "https:" + s_url, - 'tx': "https:" + b_url, - 'bd': "https:" + b_url.replace('tx.hls.huya.com', 'bd.hls.huya.com'), - 'migu-bd': "https:" + b_url.replace('tx.hls.huya.com', 'migu-bd.hls.huya.com'), + 'hls': base_url + '.m3u8', + 'flv': base_url + '.flv', + 'hls_2m': base_url + '.m3u8?ratio=2000', + 'flv_2m': base_url + '.flv?ratio=2000' } else: raise Exception('未开播或直播间不存在') @@ -45,24 +45,39 @@ class HuYa: 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('&', 3) + 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] - f = str(int(time.time() * 1e7)) + 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'] - t = '0' - h = '_'.join([p, t, s, f, ll]) + 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() - y = c[-1] - url = "{}?wsSecret={}&wsTime={}&u={}&seqid={}&{}".format(i, m, ll, t, f, y) + 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