From 8b7635d2fcb0e104f97f64a4927ad537d6520ff0 Mon Sep 17 00:00:00 2001 From: wbt5 Date: Sun, 21 Nov 2021 18:04:44 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20Improve=20KK=E7=9B=B4=E6=92=AD=20-?= =?UTF-8?q?=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 --- kk.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kk.py b/kk.py index d1da8dc..5543457 100644 --- a/kk.py +++ b/kk.py @@ -5,20 +5,24 @@ import requests class KK: def __init__(self, rid): + """ + KK直播 + Args: + rid: 房间号 + """ self.rid = rid + self.s = requests.Session() def get_real_url(self): url = 'https://sapi.kktv1.com/meShow/entrance?parameter={}' - parameter = {'FuncTag': 10005043, 'userId': '{}'.format(self.rid), 'platform': 1, 'a': 1, 'c': 100101} - with requests.Session() as s: - res = s.get(url.format(parameter)).json() + parameter = {'FuncTag': 10005043, 'userId': f'{self.rid}', 'platform': 1, 'a': 1, 'c': 100101} + res = self.s.get(url.format(parameter)).json() tagcode = res['TagCode'] if tagcode == '00000000': if res.get('liveType', 0) == 1: roomid = res['roomId'] parameter = {'FuncTag': 60001002, 'roomId': roomid, 'platform': 1, 'a': 1, 'c': 100101} - with requests.Session() as s: - res = s.get(url.format(parameter)).json() + res = self.s.get(url.format(parameter)).json() real_url = res['liveStream'] return real_url else: