|

楼主 |
发表于 2020-4-14 21:38:40
|
显示全部楼层
- #huya录播
- import requests
- import time
- import re
- headers = {
- 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
- }
- count = 0
- #因为我放在服务器运行,所以我设置了死循环定时执行
- while True:
- #获取主播主页和单页全部视频id
- count += 1#计算执行次数
- index = requests.get('https://v.huya.com/u/1259515661837/livevideo.html',headers = headers).text
- videoId = re.findall('<li data-source-client-type="1">[\s\S]*?<a target="_blank" href=\'/play/(.*?).html\' title=\'.*?\' class="statpid"',index)
- print(videoId)
- #通过评论返回的json获取原画m3u8链接,后接videoId参数
- url = 'https://liveapi.huya.com/moment/getMomentContent'
- videolink = []
- for i in videoId:
- #链接拼接
- #callback = 'jQuery112405274435378754792_1586837326054'随机可不写
-
- url2 = url + '?'+'&videoId='+i
- videojson = requests.get(url2,headers = headers).text
- videolink = videolink + re.findall('{"size":".*?","width":"1920","height":"1080","definition":".*?","url":"(.*?)"',videojson)
- #后面的m3u8播放器网址需要播放https协议,直接替换也可
- for i in range(len(videolink)):
- videolink[i] = videolink[i].replace('http://','https://')
-
- print('录播视频m3u8链接列表',videolink)
- newvideolink = '<meta http-equiv="refresh" content="1;url=\''+'https://www.qtbox.cn/zdx/m3u8jx/?url='+videolink[0]+'\';">'
- #编辑zdx.txt为html网页,默认解析第0个
- with open('zdx.txt','r',encoding = 'utf-8') as f1,open('zdx.html','w',encoding = 'utf-8') as f2:
- for line in f1:
- if '<meta http-equiv="refresh" content="1;url=\'http://test\';">' in line:
- line = line.replace('<meta http-equiv="refresh" content="1;url=\'http://test\';">',newvideolink)
- f2.write(line)
- print('第',count,'次执行成功!')
- print('写入成功')
- time.sleep(7200)
-
复制代码 |
|