import os, shutil, base64, traceback

for dirs, _, files in os.walk('.'): for file in files: if file.endswith('.m3u8'): try: key_file = [f for f in os.listdir(dirs) if f.endswith('.key')][0] with open(os.path.join(dirs, key_file), 'rb') as f: key = f.read() except: print(traceback.format_exc()) with open('error.txt', 'a+') as f: f.write(dirs + ' ') if key: if len(file.split('.')[0]): if file.split('.')[0]: filename = dirs + '.m3u8' else: filename = dirs + file.split('.')[0] + '.m3u8' print(filename) jroot = os.path.join(dirs, file) with open(jroot, 'r+', encoding='ansi') as f1: a = f1.read().splitlines() a[4] = '#EXT-X-KEY:METHOD=AES-128,URI='base64:{0}''.format(base64.b64encode(key).decode()) f1.seek(0) for line in a: f1.write(line + ' ') f1.close() try: os.rename(jroot, filename.split('')[(-1)]) except: print(traceback.format_exc()) with open('error.txt', 'a+') as f: f.write(dirs + ' ') else: jroot = os.path.join(dirs, file) with open(jroot, 'r+', encoding='ansi') as f1: a = f1.read().splitlines() a[4] = '#EXT-X-KEY:METHOD=AES-128,URI='base64:{0}''.format(base64.b64encode(key).decode()) f1.seek(0) for line in a: f1.write(line + ' ') f1.close() shutil.move(jroot, '.')

Python 3 代码修改:支持任意 .key 格式文件解密 .m3u8 文件

原文地址: https://www.cveoy.top/t/topic/ngO6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录