code wiki / _hdl_build / nx_media_nuxt_manifest_gate.nx
nx_media_nuxt_manifest_gate.nx source
↩ module page · 61 lines · 4548 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"
14
15func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
16" as *u8); return ok }
17func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
18
19func run_ex(html: *u8, want_kind: i64, want: *u8) -> i64 {
20 let best: *u8 = sys_mmap(4096); let kb: *i64 = sys_mmap(8) as *i64
21 let conf: i64 = mx_extract(html, gsl(html), best, 4096, kb)
22 if conf == 0 { gw(" (nothing found)\n" as *u8); return 0 }
23 if kb[0] != want_kind { gw(" (kind=" as *u8); gn(kb[0]); gw(" best=[" as *u8); gw(best); gw("])\n" as *u8); return 0 }
24 if xt_has(best, gsl(best), want) == 0 { gw(" (best=[" as *u8); gw(best); gw("])\n" as *u8); return 0 }
25 return 1
26}
27
28func main() -> i64 {
29 gw("nuxt-manifest SOVEREIGN gate (Nuxt-SSR + JSON videos_manifest site-class -> HLS; self-heal on CDN move)\n" as *u8)
30 var pass: i64 = 0
31 var ttl: i64 = 0
32
33 // NX1: __NUXT__ deep-nested videos_manifest (the SSR shape) -> extract the HLS master
34 ttl=ttl+1; pass=pass+grow("NX1 __NUXT__ videos_manifest.servers[].streams[].url -> HLS\x00" as *u8,
35 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))
36
37 // NX2: the raw API-JSON manifest inline (as /api/v8/video would return) -> HLS found among the streams
38 ttl=ttl+1; pass=pass+grow("NX2 inline API JSON manifest (servers/streams/url) -> HLS\x00" as *u8,
39 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))
40
41 // NX3: JSON-escaped \/ in the manifest (real API JSON escapes slashes) -> unescaped HLS
42 ttl=ttl+1; pass=pass+grow("NX3 escaped \\/ manifest url -> https://cdn.x/hls/master.m3u8\x00" as *u8,
43 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))
44
45 // NX4: SELF-HEAL -- the site MOVED its manifest to an UNSEEDED, extension-LESS CDN path (a real "site update").
46 // Default seed MISSES; after the table learns the host, the SAME orchestrator extracts it.
47 let moved: *u8 = "<script>window.__NUXT__={\"video\":{\"src\":\"https://vault-9.streamedge.example/deliver/v/abc123/index\"}}</script>" as *u8
48 let best: *u8 = sys_mmap(4096); let kb: *i64 = sys_mmap(8) as *i64
49 let miss: i64 = mx_extract(moved, gsl(moved), best, 4096, kb)
50 ttl=ttl+1; pass=pass+grow("NX4a moved manifest (unseeded ext-less CDN) MISSES default seed\x00" as *u8, (miss == 0) as i64)
51 let t: *i64 = xh_new(); xh_seed(t)
52 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)
53 let healed: i64 = mx_extract_t(moved, gsl(moved), best, 4096, kb, t)
54 var nx4b: i64 = 0
55 if healed > 0 { if kb[0] == XT_DIRECT { if xt_has(best, gsl(best), "streamedge.example" as *u8) == 1 { nx4b = 1 } } }
56 ttl=ttl+1; pass=pass+grow("NX4b after heal, SAME orchestrator extracts the moved manifest\x00" as *u8, nx4b)
57
58 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8)
59 if pass == ttl { gw("verdict=GREEN (extractor handles the Nuxt-SSR/JSON-manifest site-class; self-heals when such a site moves its CDN)\n" as *u8); sys_exit(0); return 0 }
60 gw("verdict=RED\n" as *u8); sys_exit(1); return 1
61}