code wiki / _hdl_build / nx_media_nuxt_manifest_gate.nx

nx_media_nuxt_manifest_gate.nx source

↩ module page · 69 lines · 4938 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_media_nuxt_manifest_gate.nx -- HARDENS the extractor against the Nuxt-SSR + JSON-video-manifest site-class 4// (the structure the open-source hanime-plugin documents: __NUXT__ state carrying videos_manifest -> 5// servers[].streams[].url HLS, also served by /api/v8/video). SYNTHETIC fixtures in that documented shape with 6// PLACEHOLDER hosts -- this tests whether our classifier recognizes the site-class STRUCTURE, no live pull of any 7// copyrighted stream. Ties to self-heal: if such a site moves its manifest to an UNSEEDED CDN, the table learns 8// it. license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_media_signal.nx" 11import "nx_media_state.nx" 12import "nx_media_extract.nx" 13import "nx_extract_heal.nx" 14import "nx_gate_verdict.nx" 15 16func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 17" as *u8); return ok } 18func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 19 20func run_ex(html: *u8, want_kind: i64, want: *u8) -> i64 { 21 let best: *u8 = sys_mmap(4096); let kb: *i64 = sys_mmap(8) as *i64 22 let conf: i64 = mx_extract(html, gsl(html), best, 4096, kb) 23 if conf == 0 { gw(" (nothing found)\n" as *u8); return 0 } 24 if kb[0] != want_kind { gw(" (kind=" as *u8); gn(kb[0]); gw(" best=[" as *u8); gw(best); gw("])\n" as *u8); return 0 } 25 if xt_has(best, gsl(best), want) == 0 { gw(" (best=[" as *u8); gw(best); gw("])\n" as *u8); return 0 } 26 return 1 27} 28 29func main() -> i64 { 30 gw("nuxt-manifest SOVEREIGN gate (Nuxt-SSR + JSON videos_manifest site-class -> HLS; self-heal on CDN move)\n" as *u8) 31 var pass: i64 = 0 32 var ttl: i64 = 0 33 34 // NX1: __NUXT__ deep-nested videos_manifest (the SSR shape) -> extract the HLS master 35 ttl=ttl+1; pass=pass+grow("NX1 __NUXT__ videos_manifest.servers[].streams[].url -> HLS\x00" as *u8, 36 run_ex("<script>window.__NUXT__={\"state\":{\"data\":{\"video\":{\"videos_manifest\":{\"servers\":[{\"streams\":[{\"height\":\"1080\",\"url\":\"https://cdn.example-stream.net/hls/abc/master.m3u8\"}]}]}}}}}}</script>" as *u8, XT_HLS, "https://cdn.example-stream.net/hls/abc/master.m3u8\x00" as *u8)) 37 38 // NX2: the raw API-JSON manifest inline (as /api/v8/video would return) -> HLS found among the streams 39 ttl=ttl+1; pass=pass+grow("NX2 inline API JSON manifest (servers/streams/url) -> HLS\x00" as *u8, 40 run_ex("<script>var d={\"videos_manifest\":{\"servers\":[{\"streams\":[{\"height\":\"720\",\"url\":\"https://v.streamcdn.example/x/720.m3u8\"},{\"height\":\"1080\",\"url\":\"https://v.streamcdn.example/x/1080.m3u8\"}]}]}}</script>" as *u8, XT_HLS, ".m3u8\x00" as *u8)) 41 42 // NX3: JSON-escaped \/ in the manifest (real API JSON escapes slashes) -> unescaped HLS 43 ttl=ttl+1; pass=pass+grow("NX3 escaped \\/ manifest url -> https://cdn.x/hls/master.m3u8\x00" as *u8, 44 run_ex("<script>window.__NUXT__={\"streams\":[{\"url\":\"https:\\/\\/cdn.x\\/hls\\/master.m3u8\"}]}</script>" as *u8, XT_HLS, "https://cdn.x/hls/master.m3u8\x00" as *u8)) 45 46 // NX4: SELF-HEAL -- the site MOVED its manifest to an UNSEEDED, extension-LESS CDN path (a real "site update"). 47 // Default seed MISSES; after the table learns the host, the SAME orchestrator extracts it. 48 let moved: *u8 = "<script>window.__NUXT__={\"video\":{\"src\":\"https://vault-9.streamedge.example/deliver/v/abc123/index\"}}</script>" as *u8 49 let best: *u8 = sys_mmap(4096); let kb: *i64 = sys_mmap(8) as *i64 50 let miss: i64 = mx_extract(moved, gsl(moved), best, 4096, kb) 51 ttl=ttl+1; pass=pass+grow("NX4a moved manifest (unseeded ext-less CDN) MISSES default seed\x00" as *u8, (miss == 0) as i64) 52 let t: *i64 = xh_new(); xh_seed(t) 53 xh_learn(t, "https://vault-9.streamedge.example/deliver/v/abc123/index" as *u8, gsl("https://vault-9.streamedge.example/deliver/v/abc123/index" as *u8), XT_DIRECT) 54 let healed: i64 = mx_extract_t(moved, gsl(moved), best, 4096, kb, t) 55 var nx4b: i64 = 0 56 if healed > 0 { if kb[0] == XT_DIRECT { if xt_has(best, gsl(best), "streamedge.example" as *u8) == 1 { nx4b = 1 } } } 57 ttl=ttl+1; pass=pass+grow("NX4b after heal, SAME orchestrator extracts the moved manifest\x00" as *u8, nx4b) 58 59 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 60 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 61 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 62 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 63 let ctr__dry: *i64 = gv_ctr() 64 ctr__dry[0] = pass 65 ctr__dry[1] = ttl 66 let rc__dry: i64 = gv_verdict("MEDIA-NUXT-MANIFEST-GATE" as *u8, ctr__dry, "extractor handles the Nuxt-SSR/JSON-manifest site-class; self-heals when such a site moves its CDN)" as *u8) 67 sys_exit(rc__dry) 68 return rc__dry 69}