From 0e647a7bb0ad75d60896b3e252690b47f70ac973 Mon Sep 17 00:00:00 2001 From: wbt5 Date: Thu, 13 May 2021 21:30:51 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Add=20=E4=B8=AD=E5=9B=BD=E4=BD=93?= =?UTF-8?q?=E8=82=B2=20(#166)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhibotv.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 zhibotv.py diff --git a/zhibotv.py b/zhibotv.py new file mode 100644 index 0000000..401f890 --- /dev/null +++ b/zhibotv.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# @Time: 2021/5/13 20:27 +# @Project: real-url +# @Author: wbt5 +# @Blog: https://wbt5.com + +import requests + + +class ZhiBotv: + + def __init__(self, rid): + self.rid = rid + self.params = { + + 'token': '', + 'roomId': self.rid, + 'angleId': '', + 'lineId': '', + 'definition': 'hd', + 'statistics': 'pc|web|1.0.0|0|0|0|local|5.0.1', + + } + + def get_real_url(self): + """ + no streaming 没开播; + non-existent rid 房间号不存在; + :return: url + """ + with requests.Session() as s: + res = s.get('https://rest.zhibo.tv/room/get-pull-stream-info-v430', params=self.params).json() + if 'hlsHUrl' in res['data']: + url = res['data'].get('hlsHUrl') + if url: + return url + else: + raise Exception('no streaming') + else: + raise Exception('non-existent rid') + + +def get_real_url(rid): + try: + zbtv = ZhiBotv(rid) + return zbtv.get_real_url() + except Exception as e: + print('Exception:', e) + return False + + +if __name__ == '__main__': + r = input('请输入中国体育房间号:\n') + print(get_real_url(r))