声明:代码仅作为学习交流,禁止用于违法行为,否则后果自负!
1. 获取.m3u8 文件URL后下载.ts视频流文件:
使用requests 模块 发送请求获取.m3u8 文件,通过正则表达式提取.m3u8 文件中.ts文件URL,再通过.ts文件URL爬取.ts文件,最后终端拼合.ts文件 成可播放视频,也可再转换为mp4或其他格式视频。
py文件名:test_thread.py
import _thread as thread, time
import re, os, sys
import random
# 以上为内置模块
import requests # 需要在终端 用pip3指令下载requests模块: pip3 install requests
name_id = 70032198
os.makedirs('./70032198/', exist_ok=True) # .py 文件夹下创建名 70032198 的文件夹
folder = './70032198/'
url = 'https://b-hls-01.*********.com/hls/70032198/70032198.m3u8' # .m3u8文件URL
serialNumber = 1
user_agent_list = [
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; WOW64) Gecko/20100101 Firefox/61.0",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36',
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2", # Safari
"MAC: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36",
"Windows: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, lik