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
| from Crypto.Cipher import AES import requests, os, re, time, traceback from requests.packages.urllib3.exceptions import InsecureRequestWarning from hyper.contrib import HTTP20Adapter requests.packages.urllib3.disable_warnings(InsecureRequestWarning) from tqdm import tqdm from itertools import count import re ncols = 80
def _path(name, root=None): p = os.path.join(root or os.getcwd(), name) return (os.path.exists(p) or not os.mkdir(p)) and p
def getf(id): with open(f'{id:02}.txt') as f: return f.read().split('\n\n')
_ua = re.compile(r'\nUser-Agent: (.*)\n') _ac = re.compile(r'\nAccept-Encoding: (.*)\n') _cn = re.compile(r'csrf_cookie_name=(.+?)\b') _es = re.compile(r'expires=(.+?);') _vs = re.compile(r'vpapp_session=(.+?)\b') def getHeader(a, b): c_n = _cn.findall(b)[0] e_s = _es.findall(b)[0] v_s = _vs.findall(b)[0] header = { 'user-agent': _ua.findall(a)[0], 'accept-encoding': _ac.findall(a)[0], 'cookie': f'csrf_cookie_name={c_n}; expires={e_s}; vpapp_session={v_s}; HttpOnly' } return header
_ur = re.compile(r'URI="(.+?)"') def getKey(c, header): s = requests.session() s.verify = False s.mount(r'https://', HTTP20Adapter()) URL = _ur.findall(c)[0] r = s.get(URL, headers=header) return r.content
_iv = re.compile(r',IV=(.+?)\b') def getIV(c): return _iv.findall(c)[0]
_ts = re.compile(r'\nhttps://(.+?).ts') def getTsList(c): res = _ts.findall(c) return (f'https://{x}.ts' for x in res)
def rqGet(URL, header): s = requests.session() s.verify = False s.mount(r'https://', HTTP20Adapter()) r = s.get(URL, headers=header) return r.content
def getTsData(KEY, IV, DATA, METHOD='AES-128'): if METHOD == 'AES-128': vt = IV.replace("0x", "")[:16].encode() ci = AES.new(KEY, AES.MODE_CBC, vt) content_ts = ci.decrypt(DATA) return content_ts
def dl(id): a,b,c = getf(id) header = getHeader(a, b) key = getKey(c, header) iv = getIV(c) tsl = getTsList(c) path = _path(f'{id:02}') for i,URL in enumerate(tqdm(tsl, ncols=ncols, desc=f'Dling...{id:02}...')): while True: try: d = rqGet(URL, header) d = getTsData(key, iv, d) p = os.path.join(path, f'{i:03}') with open(p, 'wb') as f: f.write(d) break except: traceback.print_exc() continue
|