会员视频下载

# !/usr/bin/python
# -*- coding: utf-8 -*-
"""
@Time    :  2022/12/7 11:15
@Author  :  Kyrie
@Version :  1.0
@License :  (C)Copyright 2021-2022
@Desc    :  None
"""
import os.path
import re

from tqdm import tqdm  # 进度条模块
import requests
from Crypto.Cipher import AES  # crypyo解密模块  安装命令:pip3 install pycryptodome


url_dict = {
    "【第14节】继往开来(全章知识点及提升总结)": "https://he/9/ef482572ee343629079_1.m3u8",
}

# 创建文件夹
file_dir = "./模块"
if not os.path.exists(file_dir):
    os.mkdir(file_dir)

for name, url in url_dict.items():
    print(f"正在处理 {name} 的下载...")
    # 1、发送请求
    response = requests.get(url)
    # 2、获取数据
    m3u8_data = response.text
    # 3、解析数据
    ts_list = re.sub("#E.*", '', m3u8_data).split()
    key_rex = re.search('.*URI="(?P<url>.*)"', m3u8_data)
    key_url = key_rex.group('url')
    # 4、遍历下载ts文件
    for ts_url in tqdm(ts_list):
        key = requests.get(key_url).content
        res_ts = requests.get(ts_url).content

        # 保存ts文件
        file_path = os.path.join(file_dir, f"./{name}.ts")
        with open(file_path, 'ab') as ts:
            # 数据解密
            cryptor = AES.new(key, AES.MODE_CBC, key)
            # 写入文件
            ts.write(cryptor.decrypt(res_ts))

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容