From a82ce4b08f82c11a5f2b6c49df0e1e9d16d2a5ce Mon Sep 17 00:00:00 2001 From: wbt5 Date: Sat, 20 Nov 2021 17:10:58 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20Improve=20=E6=88=98=E6=97=97=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=20-=E6=B7=BB=E5=8A=A0=E7=89=B9=E6=AE=8A=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=97=B4=E7=9A=84=E8=8E=B7=E5=8F=96=20-=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhanqi.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/zhanqi.py b/zhanqi.py index 35378cb..856b303 100644 --- a/zhanqi.py +++ b/zhanqi.py @@ -2,6 +2,7 @@ # 默认最高画质 import json +import re import requests @@ -9,12 +10,18 @@ import requests class ZhanQi: def __init__(self, rid): - self.rid = rid + """ + 战旗直播间有两种:一种是普通直播间号为数字或字幕;另一种是官方的主题直播间,链接带topic。 + 所以先判断一次后从网页源代码里获取数字直播间号 + Args: + rid:直播间链接,从网页源码里获取真实数字rid + """ self.s = requests.Session() + res = self.s.get(rid).text + self.rid = re.search(r'"code":"(\d+)"', res).group(1) def get_real_url(self): - - res = self.s.get('https://m.zhanqi.tv/api/static/v2.1/room/domain/{}.json'.format(self.rid)) + res = self.s.get(f'https://m.zhanqi.tv/api/static/v2.1/room/domain/{self.rid}.json') try: res = res.json() videoid = res['data']['videoId'] @@ -47,8 +54,7 @@ class ZhanQi: res = self.s.post('https://www.zhanqi.tv/api/public/burglar/chain', data=data, headers=headers).json() chain_key = res['data']['key'] url = f'https://{cdn_host}/alhdl-cdn.zhanqi.tv/zqlive/{videoid}.flv?{chain_key}&playNum=68072487067' \ - f'&gId={gid}&ipFrom=1&clientIp=&fhost=h5&platform=128 ' - + f'&gId={gid}&ipFrom=1&clientIp=&fhost=h5&platform=128' return url else: raise Exception('No streaming') @@ -64,5 +70,6 @@ def get_real_url(rid): if __name__ == '__main__': - r = input('输入战旗直播房间号:\n') + # 直播间链接类似:https://www.zhanqi.tv/topic/owl 或 https://www.zhanqi.tv/152600919 + r = input('输入战旗直播间的链接:\n') print(get_real_url(r))