源代码展示
import threading #使用多线程
import requests #使用requests请求下载
import time
import os
import re
from Crypto.Cipher import AES #需要安装pycryptodome模块,用于key解密 D:\PythonLocat\Lib\site-packages\crypto\cipher\路径下有个AES.py文件,Crypto.Cipher区分大小写,否则报错
import ctypes #禁用cmd快速编辑模式
Headers={
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
}
def disable_cmd():#禁用cmd快速编辑模式
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-10),128)
def del_log():#删除上一个视频的信息
print("布置环境……")
os.system("del *.ts") #删除ts
if os.path.exists('./filelist.txt'):
os.system("del filelist.txt")
print("正在删除 filelist.txt文件")
if os.path.exists('./contras.log'):
os.system("del contras.log")
print("正在删除 contras.log文件")
if os.path.exists('./index.m3u8'):
os.system("del index.m3u8")
print("正在删除 index.m3u8文件")
if os.path.exists('./key.m3u8'):
os.system("del key.m3u8")
print("正在删除 key.m3u8文件")
if os.path.exists('./unplayerror.log'):
os.system("del unplayerror.log")
print("正在删除 unplayerror.log文件")
if os.path.exists('./exsislist.log'):
os.system("del exsislist.log")
print("正在删除 exsislist.log文件")
os.system("cls")
def down_play_list(play_list_url,name): #下载
try:
play_url =requests.get(url=play_list_url,headers=Headers,timeout=None).content
with open (name,mode='wb') as ts:
if not key:
ts.write(play_url)
else:
cryptor = AES.new(key,AES.MODE_CBC,key) #解密
ts.write(cryptor.decrypt(play_url)) #解密后写入
except ValueError:
print(play_list_url + "第一次下载失败,尝试重新下载")
play_url=play_list_url
play_url =requests.get(url=play_list_url,headers=Head