code wiki / _hdl_build / nx_media_extract_gate.nx

nx_media_extract_gate.nx source

↩ module page · 63 lines · 4034 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" 10import "nx_gate_verdict.nx" 11 12func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 13" as *u8); return ok } 14func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 15 16func run_ex(html: *u8, want_kind: i64, want_url: *u8) -> i64 { 17 let best: *u8 = sys_mmap(4096) 18 let kb: *i64 = sys_mmap(8) as *i64 19 let conf: i64 = mx_extract(html, gsl(html), best, 4096, kb) 20 if conf == 0 { gw(" (nothing found)\n" as *u8); return 0 } 21 if kb[0] != want_kind { gw(" (kind=" as *u8); gn(kb[0]); gw(" best=[" as *u8); gw(best); gw("])\n" as *u8); return 0 } 22 if xt_has(best, gsl(best), want_url) == 0 { gw(" (best=[" as *u8); gw(best); gw("])\n" as *u8); return 0 } 23 return 1 24} 25 26func main() -> i64 { 27 gw("media-extract SOVEREIGN gate (page -> layered resilient extraction -> best media URL)\n" as *u8) 28 var pass: i64 = 0 29 var ttl: i64 = 0 30 31 // E1: __NUXT__ state with an HLS master 32 ttl=ttl+1; pass=pass+grow("E1 __NUXT__ streams -> master.m3u8 (HLS)\x00" as *u8, 33 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)) 34 // E2: inline extension-LESS YouTube-style URL (the probe gap) -> DIRECT 35 ttl=ttl+1; pass=pass+grow("E2 inline googlevideo /videoplayback -> DIRECT\x00" as *u8, 36 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)) 37 // E3: manifest beats a bare segment 38 ttl=ttl+1; pass=pass+grow("E3 [seg.ts + master.m3u8] -> m3u8 wins\x00" as *u8, 39 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)) 40 // E4: no media at all -> nothing 41 ttl=ttl+1 42 let best4: *u8 = sys_mmap(4096); let kb4: *i64 = sys_mmap(8) as *i64 43 let h4: *u8 = "<html><body><img src=\"https://c/a.jpg\"><img src=\"https://c/b.png\"></body></html>" as *u8 44 let cf4: i64 = mx_extract(h4, gsl(h4), best4, 4096, kb4) 45 pass=pass+grow("E4 images-only -> nothing found (conf 0)\x00" as *u8, (cf4 == 0) as i64) 46 // E5: JSON-escaped \/ in __NUXT__ -> unescaped HLS 47 ttl=ttl+1; pass=pass+grow("E5 escaped \\/ __NUXT__ -> https://cdn/x.m3u8\x00" as *u8, 48 run_ex("<script>window.__NUXT__={\"url\":\"https:\\/\\/cdn\\/x.m3u8\"}</script>" as *u8, XT_HLS, "https://cdn/x.m3u8\x00" as *u8)) 49 // E6: YouTube-shape player response with a videoplayback url 50 ttl=ttl+1; pass=pass+grow("E6 ytInitialPlayerResponse videoplayback -> DIRECT\x00" as *u8, 51 run_ex("<script>var ytInitialPlayerResponse={\"streamingData\":{\"formats\":[{\"url\":\"https://r.googlevideo.com/videoplayback?e=1\"}]}};</script>" as *u8, XT_DIRECT, "videoplayback\x00" as *u8)) 52 53 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 54 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 55 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 56 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 57 let ctr__dry: *i64 = gv_ctr() 58 ctr__dry[0] = pass 59 ctr__dry[1] = ttl 60 let rc__dry: i64 = gv_verdict("MEDIA-EXTRACT-GATE" as *u8, ctr__dry, "orchestrator: page -> layered resilient extraction -> ranked best media URL)" as *u8) 61 sys_exit(rc__dry) 62 return rc__dry 63}