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: