Python实操斗鱼视频下载

import requests
import re
url = r'http://play-tx-ugcpub.douyucdn2.cn/live/high_1798502320230824155125-upload-eb4e/playlist.m3u8?tlink=64f60e02\u0026tplay=64f69aa2\u0026exper=0\u0026nlimit=5\u0026us=9c6e6f91af2ec24354ab88c300081601\u0026sign=9ae855537c7c4264d2f88e13da6a13a6\u0026u=0\u0026d=9c6e6f91af2ec24354ab88c300081601\u0026ct=web\u0026vid=38757478\u0026pt=2\u0026cdn=tx'
# http://play-tx-ugcpub.douyucdn2.cn/live/high_1798502320230824155125-upload-eb4e/playlist.m3u8?tlink=64f60e02\u0026tplay=64f69aa2\u0026exper=0\u0026nlimit=5\u0026us=9c6e6f91af2ec24354ab88c300081601\u0026sign=9ae855537c7c4264d2f88e13da6a13a6\u0026u=0\u0026d=9c6e6f91af2ec24354ab88c300081601\u0026ct=web\u0026vid=38757478\u0026pt=2\u0026cdn=tx

url1 = r'https://v.douyu.com/wgapi/vodnc/front/stream/getStreamUrlWeb'
headers = {
    'User-Agent': ''
}
data = {
    'v': '220320230904',
    'did': '9c6e6f91af2ec24354ab88c300081601',
    'tt': '1639840596',
    'sign': '0e5aa17278b3086201ea59739c83317',
    'vid': 'jzOavpxXek6AveVm'
}
res1 = requests.post(url=url1, headers=headers, data=data)
print(res1.text, 'res1')
url_m3u8 = res1.json()['data']['thumb_video']['high']['url']
print(url_m3u8, 'url_height')

res = requests.get(url=url_m3u8, headers=headers)
# print(res.text)
m3u8_data = re.sub('#E.*', '', res.text).split()
# print(m3u8_data)
for ts in m3u8_data:
    print(ts)
    ts_url = 'http://play-tx-ugcpub.douyucdn2.cn/live/high_1798502320230824155125-upload-eb4e/'+ts
    ts_content = requests.get(url=url, headers=headers).content
    with open('aaa.mp4', mode='ab') as f:
        f.write(ts_content)

猜你喜欢

转载自blog.csdn.net/weixin_64974855/article/details/132679769