import os import requests import re from multiprocessing import Pool from Crypto.Cipher import AES # 这是你要保存的文件位置,可以自定义,记住\\不要丢这个。在下面的代码中写字很方便。 path = r'E:\newfilm\\' # 打开能播放你喜欢资源的网址,按F12.找到浏览器XHR选项里m3u8文件,右键复制网站,记得选择response 里面很多ts网址的。 m3u8 = 'https://youku-com.jjyl12349.com/20210517/BlYZo7Kz/1000kb/hls/index.m3u8' def get_key(m3u8): response = requests.get(m3u8).text key_link = re.search('URI=\"(.*?)\"', response).group(1) key = requests.get(key_link).text.encode('utf-8') crypto = AES.new(key, AES.MODE_CBC, key) return crypto def get_tslist(m3u8): response = requests.get(m3u8).text ts_list = re.findall('https:.*?\.ts', response) return ts_list crypto = get_key(m3u8) def down_ts(ts): res = requests.get(ts).content with open(path ts.split[-1] 'wb')as f: f.write(crypto.decrypt(res)) def rename_ts(ts_list): dict = {} k = 1 for ts in ts_list: ts = ts.split[-1] dict[ts] = '{:04d}'.format(k) '.ts' k = 1 for file in os.listdir(path): if file in dict.keys(): os.rename(path file, path dict.get(file)) def hebing(name): COMD1 = f'copy /b {path}*.ts {path}{name}.mp4' COMD2 = f'del {path}*.ts' os.system(COMD1) os.system(COMD2) if __name__ == '__main__': ts_list = get_tslist(m3u8) pool = Pool(10)#这里的数字10可以修改到你电脑核心的2倍左右,比如你的电脑是8核心,可以设置为16. pool.map(down_ts, ts_list)#执行批量下载 rename_ts(ts_list)#批量命名按顺序排列,防止电影在合成不连续。 hebing#合成mp删除其他文件ts文件。 hebing#合成mp删除其他文件ts文件。