import os, shutil, base64, traceback for dirs, _, files in os.walk('.'): for file in files: if file.endswith('.m3u8'): try: with open(f'{dirs}/encryption-f5.key', 'rb') as (f): key = f.read() except: print(traceback.format_exc()) with open('error.txt', 'a+') as (f): f.write(dirs + '\n')

        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 + '\n')

                    f1.close()
                try:
                    os.rename(jroot, filename.split('\')[(-1)])
                except:
                    print(traceback.format_exc())
                    with open('error.txt', 'a+') as (f):
                        f.write(dirs + '\n')

            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 + '\n')

                    f1.close()
                    shutil.move(jroot, '.')
Python3 代码修改:解密 .m3u8 文件并修改密钥文件名称

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

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