From a3865d88c7488cc7dc043505bc71fcb6b5cae9e8 Mon Sep 17 00:00:00 2001 From: wbt5 Date: Sat, 13 Nov 2021 21:56:49 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fix=20=E9=85=B7=E6=88=91=E8=81=9A?= =?UTF-8?q?=E6=98=9F=E7=9B=B4=E6=92=AD=20-=E6=9B=B4=E6=96=B0=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=9C=B0=E5=9D=80=20-=E5=AE=8C=E5=96=84VIP=E6=88=BF?= =?UTF-8?q?=E9=97=B4=E5=8F=B7=E7=9A=84=E8=8E=B7=E5=8F=96=20-=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E7=AB=96=E5=B1=8F=E7=9B=B4=E6=92=AD=E9=97=B4=E7=9A=84?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=20-=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kuwo.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/kuwo.py b/kuwo.py index deb61c0..1017399 100644 --- a/kuwo.py +++ b/kuwo.py @@ -1,26 +1,44 @@ # 酷我聚星直播:http://jx.kuwo.cn/ import requests +import re class KuWo: def __init__(self, rid): self.rid = rid + self.BASE_URL = 'https://jxm0.kuwo.cn/video/mo/live/pull/h5/v3/streamaddr' + self.s = requests.Session() def get_real_url(self): - with requests.Session() as s: - res = s.get('https://zhiboserver.kuwo.cn/proxy.p?src=h5&cmd=enterroom&rid={}&videotype=1&auto=1'.format(self.rid)) - res = res.json() - try: - livestatus = res['room']['livestatus'] - except KeyError: - raise Exception('房间号错误') - if livestatus == 2: - real_url = res['live']['url'] - return real_url + res = self.s.get(f'https://jx.kuwo.cn/{self.rid}').text + roomid = re.search(r"roomId: '(\d*)'", res) + if roomid: + self.rid = roomid.group(1) else: - raise Exception('未开播') + raise Exception('未开播或房间号错误') + params = { + 'std_bid': 1, + 'roomId': self.rid, + 'platform': 405, + 'version': 1000, + 'streamType': '3-6', + 'liveType': 1, + 'ch': 'fx', + 'ua': 'fx-mobile-h5', + 'kugouId': 0, + 'layout': 1, + 'videoAppId': 10011, + } + res = self.s.get(self.BASE_URL, params=params).json() + if res['data']['sid'] == -1: + raise Exception('未开播或房间号错误') + try: + url = res['data']['horizontal'][0]['httpshls'][0] + except (KeyError, IndexError): + url = res['data']['vertical'][0]['httpshls'][0] + return url def get_real_url(rid): @@ -35,4 +53,3 @@ def get_real_url(rid): if __name__ == '__main__': r = input('输入酷我聚星直播房间号:\n') print(get_real_url(r)) -