1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
import requests import os headers = { "User - Agent": "Mozilla / 5.0(Windows NT 10.0;WOW64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 84.0.4147.105 Safari / 537.36" } def download(baseurl,file_m3u8,path_in): url_list=[] with open(file_m3u8,"r") as f: for r in f.readlines(): if ".ts" in r : url_list.append(r.replace("\n","").strip()) for r in url_list: url = baseurl+r filename=os.path.join(path_in,r.split("_")[1]) try: re = requests.get(url=url,headers=headers) except Exception as e: print(e) pass with open(filename,"ab") as f: f.write(re.content) print("[*]download:"+filename) def mergeFileToMP4(pathname): os.chdir(pathname) cmd = "copy /b *.ts new.tmp" os.system(cmd) os.system('del /Q *.ts') os.system('del /Q *.mp4') os.rename("new.tmp", "new.mp4") os.chdir('..') print("merge file is :",str(os.path.join(pathname,"new.mp4"))) def key_test(key): print(len(key)) key_hex="" for c in key: tem=hex(ord(c))[2:] key_hex=key_hex+tem print(key_hex) return key_hex def decode_openssl(key,iv,path_in,path_out): for file in os.listdir(path_in): file_in=os.path.join(path_in,file) file_out = os.path.join(path_out,file) cmd=f"openssl aes-128-cbc -d -in {file_in} -out {file_out} -nosalt -iv {iv} -K {key}" print(cmd) os.system(cmd) def clear_ts(path): os.chdir(path) os.system("del /Q *.ts") def main(baseurl,key,iv,file_m3u8): basepath = os.path.split(file_m3u8)[0] basepath_in = os.path.join(basepath, "in") basepath_out = os.path.join(basepath, "out") if not os.path.exists(basepath_in): os.mkdir(basepath_in) if not os.path.exists(basepath_out): os.mkdir(basepath_out) download(baseurl=baseurl, file_m3u8=file_m3u8,path_in=basepath_in) key = key_test(key) decode_openssl(key,iv,basepath_in,basepath_out) mergeFileToMP4(basepath_out) clear_ts(basepath_in)
if __name__ == '__main__': baseurl="https://xxxxxxxxx/video/20210713/ea044c31965940559162b816ec8e152a/cloudv-transfer/" key="±úx£Ú:êh'ÿs{câ" iv="131f71ed838a8019b731be5b7f2a1703" file_m3u8="./jixian/3.m3u8" file_m3u8 = os.path.join(os.getcwd(),file_m3u8) if(os.path.exists(file_m3u8)): main(baseurl,key,iv,file_m3u8) else: print("[-]"+file_m3u8+" not found:\n")
|