获取hy直播地址
经常看直播,浏览器里不方便,而且不登陆看不了高清
所以就写了个python脚本 用python3运行 `python main.py <直播间地址>`
欢迎大家使用、讨论
```
from urllib.request import Request, urlopen
import re, sys
hds = {
'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:57.0) Gecko/20100101 Firefox/57.0",
'Accept-Encoding': "*",
'Accept-Language': "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9'
}
live_url = 'https://www.huya.com/xuanzi'
if len(sys.argv) >= 2:
live_url = sys.argv
req = Request( live_url, headers=hds)
data = None
with urlopen(req) as rq:
data = rq.read().decode("utf-8")
if not data:
print("获取页面源码失败.")
exit()
STREAM_RE = re.compile(r'"sStreamName":"([\w-]+)"')
CDN_RE = re.compile(r'"sHlsUrl":"([\\\.:/\w]+)"')
m = STREAM_RE.search(data)
m1 = CDN_RE.findall(data)
if m and m1:
sname = m.group(1)
for src in m1:
src = src.replace('\\','')
print("{}/{}.m3u8".format(src, sname))
else:
print("获取失败,可能是未开播")
``` 绅士必备啊 虎 牙有iframe版本 不登录高清看直播 很方便的 简单易懂~感谢~ 过来学习一波,嘿嘿
页:
[1]