From cb3fc148834dbb765fbb16a6aaeb21ebd86ab626 Mon Sep 17 00:00:00 2001 From: wbt5 Date: Sat, 23 May 2020 17:32:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B017=E7=9B=B4=E6=92=AD=E3=80=81?= =?UTF-8?q?=E8=99=8E=E7=89=99=E7=9B=B4=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 17live.py | 7 ++----- README.md | 2 +- huya.py | 40 +++++++++++++++++++++------------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/17live.py b/17live.py index 3674b72..01ad7c3 100644 --- a/17live.py +++ b/17live.py @@ -8,11 +8,8 @@ def get_real_url(rid): try: response = requests.get(url='https://api-dsa.17app.co/api/v1/lives/' + rid).json() real_url_default = response.get('rtmpUrls')[0].get('url') - userID = response.get('userID', 0) - real_url_wansu = '' - if userID: - real_url_wansu = 'http://wansu-china-pull-rtmp-17.tigafocus.com/vod/' + userID + '.flv' - real_url = [real_url_default, real_url_wansu] + real_url_modify = real_url_default.replace('global-pull-rtmp.17app.co', 'china-pull-rtmp-17.tigafocus.com') + real_url = [real_url_modify, real_url_default] except: real_url = '该直播间不存在或未开播' return real_url diff --git a/README.md b/README.md index 5d0557a..ce0c180 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ ## 更新 -### 2020.05.23:更新 17直播 +### 2020.05.23:更新17直播、虎牙直播 2020.05.19:更新火猫、快手、酷狗、PPS diff --git a/huya.py b/huya.py index 20a70f6..b95705f 100644 --- a/huya.py +++ b/huya.py @@ -7,26 +7,28 @@ import re def get_real_url(room_id): - room_url = 'https://m.huya.com/' + str(room_id) - header = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) ' - 'Chrome/75.0.3770.100 Mobile Safari/537.36 ' - } - response = requests.get(url=room_url, headers=header) - pattern = r"src=\"([\s\S]*)\" data-setup" - pattern2 = r"replay" # 判断是否是回放 - result = re.findall(pattern, response.text, re.I) - if re.search(pattern2, response.text): - return result[0] - if result: - url = re.sub(r'_[\s\S]*.m3u8', '.m3u8', result[0]) # 修改了正则留下了密钥和时间戳 - url = re.sub(r'hw.hls', 'al.hls', url) # 华为的源好像比阿里的卡 - else: - url = '未开播或直播间不存在' - return "https:" + url + try: + room_url = 'https://m.huya.com/' + str(room_id) + header = { + 'Content-Type': 'application/x-www-form-urlencoded', + 'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/75.0.3770.100 Mobile Safari/537.36 ' + } + response = requests.get(url=room_url, headers=header).text + liveLineUrl = re.findall(r'liveLineUrl = "([\s\S]*?)";', response)[0] + if liveLineUrl: + if 'replay' in liveLineUrl: + return '直播录像:' + liveLineUrl + else: + real_url = ["https:" + liveLineUrl.replace('_2500', ''), "https:" + liveLineUrl] + else: + real_url = '未开播或直播间不存在' + except: + real_url = '未开播或直播间不存在' + return real_url rid = input('请输入虎牙房间号:\n') real_url = get_real_url(rid) -print('该直播间源地址为:\n' + real_url) +print('该直播间源地址为:') +print(real_url) \ No newline at end of file