欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何下载和整合M3U8格式的影片与小电影?包括破解教程和下载方法

最编程 2024-01-14 19:05:06
...
from concurrent.futures import ThreadPoolExecutor
from Crypto.Cipher import AES
import requests,os,uuid
# 合并文件
def merge():
tmp = []
for root, dirs, files in os.walk("video/"):
for f in files:
if f.split(".", 1)[1] == "ts":
tmp.append(int(f.split(".", 1)[0]))
tmp.sort()
for i in range(len(tmp)):
tmp[i] = f"{tmp[i]}.ts"
shell_str = '+'.join(tmp)
shell_str = 'copy /b ' + shell_str + ' ' + "0.ts"
os.chdir(os.path.join(os.getcwd(), "video"))
os.system(shell_str)

# 接下来复制,并且转换成MP4
shell_str = f"copy /b 0.ts {uuid.uuid1()}.mp4"
os.system(shell_str)
os.system('del /Q *.ts')
print("整合完毕,快去看吧")

def downVideo(obj,key=None):
print(f"正在下载第{obj['num']}")
url = obj["url"]
res = requests.get(url)
key = "fad2a57ccb9deefc".encode("utf-8")
cryptor = AES.new(key, AES.MODE_CBC, b'qqqqqqqqqqqqqqqq')
with open(f"video/{obj['num']}.ts",'ab')as fp:
fp.write(cryptor.decrypt(res.content))

def start(file_src="index.m3u8"):
# 创建目录
if not os.path.isdir("video"):
os.mkdir("video")
file_src = "index.m3u8"
arr = []
with open(file_src)as f:
index = 1
for line in f.readlines():
if "#" not in line:
obj = {}
obj["url"] = line.replace("\n", "")
obj["num"] = index
index = index + 1
arr.append(obj)
return arr


if __name__ == "__main__":
# 准备工作
arr = start()
# 利用线程池 下载视频
tps = ThreadPoolExecutor(10) # 最大线程数
for obj in arr:
tps.submit(downVideo, obj)
tps.shutdown()
# 下载完毕自动整合数据
merge()

推荐阅读