code wiki / _hdl_build / nx_roku_catalog_emit.nx
nx_roku_catalog_emit.nx source
↩ module page · 43 lines · 3069 B
1// nx_roku_catalog_emit.nx -- SOVEREIGN Roku media-catalog FEED emitter (R1b). Emits catalog.json -- the media
2// data backbone the Roku channel fetches at runtime (the Jellyfin/Plex model: thin client, server holds the
3// catalog). Each item = {id,title,kind,poster}. This is the generated-media NAMESPACE feed (kept separate from
4// any personal archive by construction). The feed is published to the server (nx_aw_push) as a GATED, outward-
5// facing step -- NOT done here. Emitted by an organ, never hand-written. license_tier: ORIGINAL
6// nx_roku_catalog_emit [out.json] (default /mnt/c/Users/elder/nishi_roku_catalog.json)
7import "nx_syscalls.nx"
8const K_MAGIC_16384: i64 = 16384
9
10func rk_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func rk_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0{bb[0]=48 as u8;sys_write(1,bb,1);return 0}; let t: *u8=sys_mmap(28); while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
12func rk_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
13func rk_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ dst[off+i]=s[i]; i=i+1 } return off+i }
14
15// emit one {"id":..,"title":..,"kind":"image","poster":..} item; last=1 omits trailing comma
16func emit_item(buf: *u8, off: i64, id: *u8, title: *u8, poster: *u8, last: i64) -> i64 {
17 var o: i64=off
18 o=rk_cat(buf, o, " {\"id\":\"" as *u8); o=rk_cat(buf, o, id)
19 o=rk_cat(buf, o, "\",\"title\":\"" as *u8); o=rk_cat(buf, o, title)
20 o=rk_cat(buf, o, "\",\"kind\":\"image\",\"poster\":\"" as *u8); o=rk_cat(buf, o, poster)
21 o=rk_cat(buf, o, "\"}" as *u8)
22 if last==0 { o=rk_cat(buf, o, "," as *u8) }
23 o=rk_cat(buf, o, "\n" as *u8)
24 return o
25}
26
27func main(argc: i64, argv: *i64) -> i64 {
28 var outpath: *u8="/mnt/c/Users/elder/nishi_roku_catalog.json" as *u8
29 if argc>=2 { outpath=argv[1] as *u8 }
30 let buf: *u8=sys_mmap(K_MAGIC_16384); var o: i64=0
31 o=rk_cat(buf, o, "{\"version\":1,\"namespace\":\"generated\",\"items\":[\n" as *u8)
32 o=emit_item(buf, o, "img1" as *u8, "Sunrise" as *u8, "posters/poster1.png" as *u8, 0)
33 o=emit_item(buf, o, "img2" as *u8, "Forest" as *u8, "posters/poster2.png" as *u8, 0)
34 o=emit_item(buf, o, "img3" as *u8, "Ocean" as *u8, "posters/poster3.png" as *u8, 0)
35 o=emit_item(buf, o, "img4" as *u8, "Desert" as *u8, "posters/poster4.png" as *u8, 0)
36 o=emit_item(buf, o, "img5" as *u8, "Aurora" as *u8, "posters/poster5.png" as *u8, 0)
37 o=emit_item(buf, o, "img6" as *u8, "City" as *u8, "posters/poster6.png" as *u8, 1)
38 o=rk_cat(buf, o, "]}\n" as *u8)
39 let fd: i64=sys_openat_wr(outpath, 0x1a4); if fd<0 { rk_puts("ROKU-CATALOG-EMIT-FAIL (open)\n" as *u8); sys_exit(1); return 1 }
40 sys_write(fd, buf, o); sys_close(fd)
41 rk_puts("ROKU-CATALOG-EMIT-OK path=" as *u8); rk_puts(outpath); rk_puts(" bytes=" as *u8); rk_num(o); rk_puts(" items=6\n" as *u8)
42 sys_exit(0); return 0
43}