From 2db1b08b744c40ff095b1b6dbee8431846e53dbf Mon Sep 17 00:00:00 2001 From: wbt5 Date: Sat, 20 Nov 2021 23:00:49 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fix=20=E4=B8=80=E7=9B=B4=E6=92=AD=20-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F=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 --- yizhibo.py | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/yizhibo.py b/yizhibo.py index b52b131..d70e1b0 100644 --- a/yizhibo.py +++ b/yizhibo.py @@ -7,33 +7,24 @@ import re class YiZhiBo: def __init__(self, rid): + """ + 一直播需要传入直播间的完整地址 + Args: + rid:完整地址 + """ self.rid = rid + self.s = requests.Session() def get_real_url(self): try: - scid = re.findall(r'/l/(\S*).html', self.rid)[0] - flvurl = 'http://alcdn.f01.xiaoka.tv/live/{}.flv'.format(scid) - m3u8url = 'http://al01.alcdn.hls.xiaoka.tv/live/{}.m3u8'.format(scid) - rtmpurl = 'rtmp://alcdn.r01.xiaoka.tv/live/live/{}'.format(scid) - real_url = { - 'flvurl': flvurl, - 'm3u8url': m3u8url, - 'rtmpurl': rtmpurl - } - except: - raise Exception('链接错误') - return real_url - - def get_status(self): - try: - scid = re.findall(r'/l/(\S*).html', self.rid)[0] - response = requests.get( - url='https://m.yizhibo.com/www/live/get_live_video?scid=' + str(scid)).json() - status_code = response.get('data').get('info').get('status') - status = '直播中' if status_code == 10 else '未开播' - except: - raise Exception('链接错误') - return status + res = self.s.get(self.rid).text + play_url, status_code = re.findall(r'play_url:"(.*?)"[\s\S]*status:(\d+),', res)[0] + if status_code == '10': + return play_url + else: + raise Exception('未开播') + except Exception: + raise Exception('获取错误') def get_real_url(rid):