code wiki / (root) / nx_hls_get.nx

nx_hls_get.nx

buildroot/runtime/nx_hls_get.nx

15183 B229 linesdepth 22pulls 134 transitivereach 0 importersview sourcekind tooltopic hls
docsdependenciesstructsconstsfunctions

about

nx_hls_get.nx -- X-DLP rung 2: the HLS DOWNLOAD ORCHESTRATOR. Turns an .m3u8 URL into ONE stitched .ts file the gallery can ingest + the operator can watch. Composes the gated rung 0 (nx_hls_parse) + rung 1 (nx_hls_resolve) + the UA/Referer/Cookie-aware fetch (nx_video_get's nx_video_fetch): fetch playlist -> if MASTER pick the highest-bandwidth variant -> fetch its media playlist -> resolve EVERY segment URI to absolute -> fetch each in order -> CONCAT into outpath. FORK-PER-SEGMENT: each segment is fetched in a child that exits, so the TLS stack's per-fetch mmap leak dies with the child (no OOM over hundreds of segments) -- same isolation idiom as the connect researcher. CLEAR + AES-128 (#EXT-X-KEY, rung 3 via nx_aes_cbc) HLS handled here; daemon wiring = rung 4; fMP4/#EXT-X-MAP (init segment) = a later rung (MPEG-TS .ts concatenates cleanly, fMP4 does not). argv[1]=m3u8 url argv[2]=outpath(.ts) argv[3]=referer argv[4]=cookie. license_tier: ORIGINAL module: nishi-core.media.hls_get

dependencies 7 imports · 0 importers

nx_hls_resolve.nx nx_video_get.nx nx_x509_trust_store.nx nx_pem_loader.nx nx_aes.nx nx_aes_cbc.nx nx_syscalls.nx nx_hls_get.nx

imports: nx_hls_resolve.nxnx_video_get.nxnx_x509_trust_store.nxnx_pem_loader.nxnx_aes.nxnx_aes_cbc.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main hg_w sys_write sys_exit trust_store_alloc sys_mmap nx_pem_trust_load_file sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close nx_pem_trust_load nx_str_len _pem_find nx_str_len ↻ sys_mmap ↻ b64_decode b64_grab b64_dec_char x509_parse sys_mmap ↻ asn1_cursor_init asn1_expect_tag sys_mmap ↻ asn1_read_tlv_header asn1_read_tag asn1_read_length asn1_read_length ↻ x509_read_tlv sys_mmap ↻ asn1_expect_tag ↻ x509_read_alg_id sys_mmap ↻ asn1_expect_tag ↻ trust_store_add sys_now_realtime_sec sys_mmap ↻

structs

none

consts

19const HG_MAGIC_8192: i64 = 8192
20const HG_MAGIC_4096: i64 = 4096
131const HG_MAXENT: i64 = 20000 // max segments / variants
132const HG_PLCAP: i64 = 4194304 // 4 MiB playlist buffer
133const HG_SEGCAP: i64 = 33554432 // 32 MiB per-segment buffer (HLS .ts segments are typically a few MiB)

functions

22func hg_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
23func hg_wn(v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let b: *u8=sys_mmap(28); var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
24func hg_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 2: hg_find_aftermain
27func hg_readfile(path: *u8, buf: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
34func hg_append(fd: i64, buf: *u8, n: i64) -> i64 { var o: i64 = 0; while o < n { let w: i64 = sys_write(fd, (buf as i64 + o) as *u8, n - o); if w <= 0 { return 0 - 1 } o = o + w } return 0 }
called by 1: main calls 1: sys_write
38func hg_fetch(url: *u8, referer: *u8, cookie: *u8, partpath: *u8, store: *TrustStore, now: i64) -> i64
51func hg_find_after(buf: *u8, n: i64, lit: *u8) -> i64
called by 2: hg_parse_keyhg_media_seq calls 1: hg_slen
57func hg_hexv(c: i64) -> i64 { if c>=48 { if c<=57 { return c-48 } } if c>=97 { if c<=102 { return c-97+10 } } if c>=65 { if c<=70 { return c-65+10 } } return 0 - 1 }
called by 1: hg_parse_key
61func hg_parse_key(pl: *u8, pllen: i64, keyuri: *u8, uricap: i64, ivout: *u8, has_iv: *i64) -> i64
called by 1: main calls 2: hg_find_afterhg_hexv
85func hg_media_seq(pl: *u8, pllen: i64) -> i64
called by 1: main calls 1: hg_find_after
93func hg_seq_iv(seq: i64, iv: *u8) -> i64
called by 1: main
101func hg_mp4_path(ts: *u8, out: *u8) -> i64
109func hg_remux(tspath: *u8, mp4path: *u8) -> i64
135func main(argc: i64, argv: *i64) -> i64