code wiki / _hdl_build / nx_yt_probe.nx
nx_yt_probe.nx source
↩ module page · 89 lines · 5620 B
1// nx_yt_probe.nx -- capability test: fetch a YouTube watch page, extract ytInitialPlayerResponse (embedded
2// state), and report HOW FAR our extractor gets -- direct stream URLs vs signatureCipher (which needs the
3// base.js sig/nsig extractor). Honest assessment, no download. Run from nxc2 root. license_tier: ORIGINAL
4import "nx_syscalls.nx"
5import "nx_x509_trust_store.nx"
6import "nx_trust_store_load_from_certdata.nx"
7import "nx_https_fetch_follow.nx"
8import "nx_media_state.nx"
9import "nx_media_signal.nx"
10import "nx_media_extract.nx"
11const K_MAGIC_4194304: i64 = 4194304
12const K_MAGIC_8388608: i64 = 8388608
13const K_MAGIC_262144: i64 = 262144
14const K_MAGIC_4096: i64 = 4096
15const K_MAGIC_1024: i64 = 1024
16
17func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
18func pn(v: i64) -> i64 { let b: *u8=sys_mmap(24); var m: i64=v; if m<0{pw("-" as *u8);m=0-m} let t: *u8=sys_mmap(24); 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} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
19func pslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
20func count_occ(hay: *u8, hl: i64, needle: *u8) -> i64 {
21 let nl: i64 = pslen(needle)
22 var c: i64 = 0
23 var i: i64 = ms_find(hay, hl, needle, nl, 0)
24 while i >= 0 { c = c + 1; i = ms_find(hay, hl, needle, nl, i + nl) }
25 return c
26}
27
28func main(argc: i64, argv: *i64) -> i64 {
29 var url: *u8 = "https://www.youtube.com/watch?v=DtBUSSrSw34" as *u8
30 if argc >= 2 { url = argv[1] as *u8 }
31 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
32 if r <= 0 { pw("YT-PROBE: certdata load failed (run from nxc2 root)\n" as *u8); sys_exit(1); return 1 }
33 let store: *TrustStore = r as *TrustStore
34 let status: *i64 = sys_mmap(8) as *i64
35
36 pw("== nx_yt_probe ==\nurl: " as *u8); pw(url); pw("\n" as *u8)
37 let cap: i64 = K_MAGIC_8388608
38 let html: *u8 = sys_mmap(cap)
39 let hn: i64 = nx_https_fetch_follow(url, store, html, cap, 6, status)
40 pw("fetch status=" as *u8); pn(status[0]); pw(" bytes=" as *u8); pn(hn); pw("\n" as *u8)
41 if hn <= 0 { pw("YT-PROBE: fetch FAILED\n" as *u8); sys_exit(1); return 1 }
42
43 // ground-truth signals across the FULL HTML (independent of my extraction)
44 pw("-- FULL HTML ground-truth signals --\n" as *u8)
45 pw(" ytInitialPlayerResponse: " as *u8); pn(count_occ(html, hn, "ytInitialPlayerResponse" as *u8)); pw("\n" as *u8)
46 pw(" consent.youtube (block): " as *u8); pn(count_occ(html, hn, "consent.youtube" as *u8)); pw("\n" as *u8)
47 pw(" streamingData: " as *u8); pn(count_occ(html, hn, "streamingData" as *u8)); pw("\n" as *u8)
48 pw(" adaptiveFormats: " as *u8); pn(count_occ(html, hn, "adaptiveFormats" as *u8)); pw("\n" as *u8)
49 pw(" signatureCipher (ciphered URLs): " as *u8); pn(count_occ(html, hn, "signatureCipher" as *u8)); pw("\n" as *u8)
50 pw(" videoplayback (stream path): " as *u8); pn(count_occ(html, hn, "videoplayback" as *u8)); pw("\n" as *u8)
51 pw(" googlevideo (CDN host): " as *u8); pn(count_occ(html, hn, "googlevideo" as *u8)); pw("\n" as *u8)
52 pw(" base.js (player script): " as *u8); pn(count_occ(html, hn, "base.js" as *u8)); pw("\n" as *u8)
53 pw(" &n= (throttle param): " as *u8); pn(count_occ(html, hn, "n=" as *u8)); pw("\n" as *u8)
54
55 // extract the player response blob
56 let blob: *u8 = sys_mmap(cap)
57 let bl: i64 = ms_extract_state(html, hn, "ytInitialPlayerResponse" as *u8, blob, cap)
58 pw("-- ytInitialPlayerResponse blob --\n" as *u8)
59 pw(" extracted bytes: " as *u8); pn(bl); pw("\n" as *u8)
60 if bl > 0 {
61 pw(" \"signatureCipher\" (ciphered URLs): " as *u8); pn(count_occ(blob, bl, "signatureCipher" as *u8)); pw("\n" as *u8)
62 pw(" \"googlevideo.com\" (CDN host refs): " as *u8); pn(count_occ(blob, bl, "googlevideo.com" as *u8)); pw("\n" as *u8)
63 pw(" \"itag\" (format entries): " as *u8); pn(count_occ(blob, bl, "itag" as *u8)); pw("\n" as *u8)
64 pw(" \"mimeType\": " as *u8); pn(count_occ(blob, bl, "mimeType" as *u8)); pw("\n" as *u8)
65 pw(" \"\\\"n\\\":\" n-param present: " as *u8); pn(count_occ(blob, bl, "&n=" as *u8)); pw("\n" as *u8)
66 let streams: *u8 = sys_mmap(K_MAGIC_262144)
67 let ns: i64 = ms_find_streams(blob, bl, streams, K_MAGIC_262144)
68 pw(" DIRECT (un-ciphered) media URLs found: " as *u8); pn(ns); pw("\n" as *u8)
69 if ns > 0 { pw(" first direct URLs:\n" as *u8); pw(streams); pw("\n" as *u8) }
70 }
71 // intelligent orchestrator on the REAL page: layered + resilient classify+rank
72 pw("-- intelligent orchestrator (mx_extract) --\n" as *u8)
73 let best: *u8 = sys_mmap(K_MAGIC_4096)
74 let kb: *i64 = sys_mmap(8) as *i64
75 let conf: i64 = mx_extract(html, hn, best, K_MAGIC_4096, kb)
76 pw(" best media kind: " as *u8); pn(kb[0]); pw(" confidence: " as *u8); pn(conf); pw("\n" as *u8)
77 if conf > 0 {
78 pw(" best URL (first 64 chars): " as *u8)
79 var q: i64 = 0
80 while q < 64 { if (best[q]&0xff) == 0 { q = 64 } else { sys_write(1, ((best as i64)+q) as *u8, 1); q = q + 1 } }
81 pw("\n" as *u8)
82 }
83 let title: *u8 = sys_mmap(K_MAGIC_1024)
84 let tl: i64 = xt_extract_title(html, hn, title, K_MAGIC_1024)
85 pw(" smart-name title (" as *u8); pn(tl); pw(" chars): " as *u8); if tl > 0 { sys_write(1, title, tl) } pw("\n" as *u8)
86 pw("== assessment: extraction works if blob>0; conf>0 = orchestrator found a candidate; signatureCipher>0 = needs base.js sig ==\n" as *u8)
87 sys_exit(0)
88 return 0
89}