code wiki / _hdl_build / nx_media_extract_gate.nx

nx_media_extract_gate.nx source

↩ module page · 55 lines · 3650 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_media_extract_gate.nx -- proves the orchestrator: HTML page -> run layers (raw + __NUXT__ + player 4// response) -> resilient classify+rank -> best media URL. Covers embedded-state, inline extension-less 5// (YouTube), escaped \/, manifest-beats-segment, and no-media. license_tier: ORIGINAL expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_media_signal.nx" 8import "nx_media_state.nx" 9import "nx_media_extract.nx" 10 11func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 12" as *u8); return ok } 13func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 14 15func run_ex(html: *u8, want_kind: i64, want_url: *u8) -> i64 { 16 let best: *u8 = sys_mmap(4096) 17 let kb: *i64 = sys_mmap(8) as *i64 18 let conf: i64 = mx_extract(html, gsl(html), best, 4096, kb) 19 if conf == 0 { gw(" (nothing found)\n" as *u8); return 0 } 20 if kb[0] != want_kind { gw(" (kind=" as *u8); gn(kb[0]); gw(" best=[" as *u8); gw(best); gw("])\n" as *u8); return 0 } 21 if xt_has(best, gsl(best), want_url) == 0 { gw(" (best=[" as *u8); gw(best); gw("])\n" as *u8); return 0 } 22 return 1 23} 24 25func main() -> i64 { 26 gw("media-extract SOVEREIGN gate (page -> layered resilient extraction -> best media URL)\n" as *u8) 27 var pass: i64 = 0 28 var ttl: i64 = 0 29 30 // E1: __NUXT__ state with an HLS master 31 ttl=ttl+1; pass=pass+grow("E1 __NUXT__ streams -> master.m3u8 (HLS)\x00" as *u8, 32 run_ex("<html><body><script>window.__NUXT__={\"streams\":[{\"url\":\"https://cdn/master.m3u8\"}]}</script></body></html>" as *u8, XT_HLS, "https://cdn/master.m3u8\x00" as *u8)) 33 // E2: inline extension-LESS YouTube-style URL (the probe gap) -> DIRECT 34 ttl=ttl+1; pass=pass+grow("E2 inline googlevideo /videoplayback -> DIRECT\x00" as *u8, 35 run_ex("<html><body><script>fetch(\"https://r3.googlevideo.com/videoplayback?itag=22&mime=x\")</script></body></html>" as *u8, XT_DIRECT, "videoplayback\x00" as *u8)) 36 // E3: manifest beats a bare segment 37 ttl=ttl+1; pass=pass+grow("E3 [seg.ts + master.m3u8] -> m3u8 wins\x00" as *u8, 38 run_ex("<script>var d={\"seg\":\"https://c/s1.ts\",\"hls\":\"https://c/master.m3u8\"}</script>" as *u8, XT_HLS, "https://c/master.m3u8\x00" as *u8)) 39 // E4: no media at all -> nothing 40 ttl=ttl+1 41 let best4: *u8 = sys_mmap(4096); let kb4: *i64 = sys_mmap(8) as *i64 42 let h4: *u8 = "<html><body><img src=\"https://c/a.jpg\"><img src=\"https://c/b.png\"></body></html>" as *u8 43 let cf4: i64 = mx_extract(h4, gsl(h4), best4, 4096, kb4) 44 pass=pass+grow("E4 images-only -> nothing found (conf 0)\x00" as *u8, (cf4 == 0) as i64) 45 // E5: JSON-escaped \/ in __NUXT__ -> unescaped HLS 46 ttl=ttl+1; pass=pass+grow("E5 escaped \\/ __NUXT__ -> https://cdn/x.m3u8\x00" as *u8, 47 run_ex("<script>window.__NUXT__={\"url\":\"https:\\/\\/cdn\\/x.m3u8\"}</script>" as *u8, XT_HLS, "https://cdn/x.m3u8\x00" as *u8)) 48 // E6: YouTube-shape player response with a videoplayback url 49 ttl=ttl+1; pass=pass+grow("E6 ytInitialPlayerResponse videoplayback -> DIRECT\x00" as *u8, 50 run_ex("<script>var ytInitialPlayerResponse={\"streamingData\":{\"formats\":[{\"url\":\"https://r.googlevideo.com/videoplayback?e=1\"}]}};</script>" as *u8, XT_DIRECT, "videoplayback\x00" as *u8)) 51 52 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 53 if pass == ttl { gw("verdict=GREEN (orchestrator: page -> layered resilient extraction -> ranked best media URL)\n" as *u8); sys_exit(0); return 0 } 54 gw("verdict=RED\n" as *u8); sys_exit(1); return 1 55}