对下载t好的ts视频进行解密 D:\data\video\m1\ 为解密后ts存放的路径
def jiemi():
f = open("./丛林奇航.m3u8", "r", encoding="utf-8")
keys = []
for file in f:
key = re.findall(r'URI="(.*?)"', file) # 用正则匹配出 key
if key:
keys.append(key[0])
key_url = keys[0]
resp4 = requests.get(key_url)
key = resp4.text
key = key.encode("utf-8")
aes = AES.new(key=key, IV=b"0000000000000000", mode=AES.MODE_CBC)
download_path = "D:\\data\\movie_ts\\m1"
all_ts = os.listdir(download_path)
li = []
for i in all_ts:
i = i.split(".")[0]
li.append(int(i))
li.sort()
for i in li:
with open(f"D:\\data\\movie_ts\\m1\\{i}.ts", mode="rb") as f1, \
open(f"D:\\data\\video\\m1\\2000{i}.ts", mode="wb") as f2:
bs = f1.read()
f2.write(aes.decrypt(bs))
print(f"第{i}视频处理完毕")