nx_hls_get.nx
buildroot/runtime/nx_hls_get.nx
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
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
structs
| none |
consts
| 19 | const HG_MAGIC_8192: i64 = 8192 |
| 20 | const HG_MAGIC_4096: i64 = 4096 |
| 131 | const HG_MAXENT: i64 = 20000 // max segments / variants |
| 132 | const HG_PLCAP: i64 = 4194304 // 4 MiB playlist buffer |
| 133 | const HG_SEGCAP: i64 = 33554432 // 32 MiB per-segment buffer (HLS .ts segments are typically a few MiB) |
functions
| 22 | func 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 } |
| 23 | func 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 } |
| 24 | func hg_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 27 | func hg_readfile(path: *u8, buf: *u8, cap: i64) -> i64 |
| 34 | func 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 } |
| 38 | func hg_fetch(url: *u8, referer: *u8, cookie: *u8, partpath: *u8, store: *TrustStore, now: i64) -> i64 |
| 51 | func hg_find_after(buf: *u8, n: i64, lit: *u8) -> i64 |
| 57 | func 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 |
| 61 | func hg_parse_key(pl: *u8, pllen: i64, keyuri: *u8, uricap: i64, ivout: *u8, has_iv: *i64) -> i64 |
| 85 | func hg_media_seq(pl: *u8, pllen: i64) -> i64 |
| 93 | func hg_seq_iv(seq: i64, iv: *u8) -> i64 called by 1: main |
| 101 | func hg_mp4_path(ts: *u8, out: *u8) -> i64 |
| 109 | func hg_remux(tspath: *u8, mp4path: *u8) -> i64 |
| 121 | func hg_gallery_refresh() -> i64 |
| 135 | func main(argc: i64, argv: *i64) -> i64 |