streamd: optional keys, per-stream proxy, auto deps; agent module.yaml sync; RTE AutoPlay; Telegram release announces
All checks were successful
release / build-and-upload (push) Successful in 6m20s
modules-release / build-and-upload (push) Successful in 4m51s

- streamd: MPD-only start, proxy field, ffmpeg/NRE/mp4decrypt auto-install
- GET/PUT /api/modules for module.yaml sync; agent sync_modules
- RTE Live-tab AutoPlay fixes; modules zip named bbc/rte/tg4.zip
- Telegram notify scripts wired into Forgejo release workflows
This commit is contained in:
404errordeveloper 2026-10-09 00:17:23 +02:00
parent f9c28be3f1
commit ac8701b5a6
36 changed files with 1460 additions and 143 deletions

View file

@ -1,7 +1,7 @@
# Always-on credentials agent (apps/agent → bin/agent.exe)
# Default path: apps/agent/agent.yaml
streamd_url: http://127.0.0.1:8083
# Must match streamd --token / STREAMD_TOKEN (mutating API: claim, credentials).
streamd_url: http://185.18.221.132:8083
# Must match streamd --token / STREAMD_TOKEN (mutating API: claim, credentials, modules).
token: "SECRET"
# Stable id across restarts (default = hostname). Required for reclaim after crash.
# agent_id: my-agent
@ -11,8 +11,10 @@ workers: 1 # concurrent ADB jobs
max_attempts: 5
capture_wait_sec: 180
devices: [] # empty = all adb "device" serials; never installs apps
# Push local modules/<name>/module.yaml to streamd when missing or SHA differs.
sync_modules: true
# modules_dir: modules # optional override (default: repo modules/)
# modules_sync_interval_sec: 300
# wvd: data/device.wvd # path to .wvd (required for key fetch)
# user_agent: "" # optional license-request User-Agent
# App modules (rte, tg4, …) are compiled into the binary — there is no
# modules directory to point at. Their local values live in
# apps/modules/<name>/module.yaml; see apps/modules/README.md.

View file

@ -15,6 +15,7 @@ import (
"drmdecryption/apps/agent/internal/client"
"drmdecryption/apps/agent/internal/config"
"drmdecryption/apps/agent/internal/device"
"drmdecryption/apps/agent/internal/modsync"
"drmdecryption/apps/agent/internal/poller"
"drmdecryption/apps/agent/internal/queue"
"drmdecryption/apps/agent/internal/worker"
@ -116,6 +117,17 @@ func runCmd(sub string, args []string) {
}
go p.Loop(stop)
if cfg.SyncModules {
ms := &modsync.Syncer{
API: api,
ModulesDir: cfg.ModulesDir,
Interval: cfg.ModulesSyncInterval(),
Log: log.Default(),
}
go ms.Loop(stop)
log.Printf("modules sync enabled interval=%s", cfg.ModulesSyncInterval())
}
ws := wsclient.New(cfg.StreamdURL, cfg.Token, cfg.AgentID, log.Default())
go ws.Loop()

View file

@ -85,6 +85,50 @@ func (c *Client) PostCredentials(id int64, cred Credentials) error {
return err
}
// ModuleInfo is one modules/<name>/ entry from GET /api/modules.
type ModuleInfo struct {
Name string `json:"name"`
HasYAML bool `json:"has_yaml"`
YAMLSHA256 string `json:"yaml_sha256,omitempty"`
}
func (c *Client) ListModules() ([]ModuleInfo, error) {
body, err := c.do(http.MethodGet, "/api/modules", nil)
if err != nil {
return nil, err
}
var wrap struct {
Modules []ModuleInfo `json:"modules"`
}
if err := json.Unmarshal(body, &wrap); err != nil {
return nil, err
}
return wrap.Modules, nil
}
// PutModuleYAML uploads raw module.yaml bytes for name (Content-Type text/yaml).
func (c *Client) PutModuleYAML(name string, yamlBytes []byte) error {
req, err := http.NewRequest(http.MethodPut, c.BaseURL+"/api/modules/"+name, bytes.NewReader(yamlBytes))
if err != nil {
return err
}
req.Header.Set("Content-Type", "text/yaml")
req.Header.Set("User-Agent", c.UserAgent)
if c.Token != "" {
req.Header.Set("Authorization", "Bearer "+c.Token)
}
resp, err := c.HTTP.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode >= 300 {
return fmt.Errorf("PUT /api/modules/%s: %s — %s", name, resp.Status, strings.TrimSpace(string(body)))
}
return nil
}
func (c *Client) do(method, path string, payload any) ([]byte, error) {
var rdr io.Reader
if payload != nil {

View file

@ -23,6 +23,10 @@ type Config struct {
WVD string `yaml:"wvd"` // path to .wvd device file (required for key fetch)
UserAgent string `yaml:"user_agent"`
AgentID string `yaml:"agent_id"`
// SyncModules pushes local modules/<name>/module.yaml to streamd when missing/stale.
SyncModules bool `yaml:"sync_modules"`
ModulesDir string `yaml:"modules_dir"` // empty = repo modules/
ModulesSyncIntervalSec int `yaml:"modules_sync_interval_sec"`
}
func (c Config) PollInterval() time.Duration {
@ -100,5 +104,18 @@ func applyDefaults(cfg Config, root string) Config {
if cfg.WVD != "" && !filepath.IsAbs(cfg.WVD) {
cfg.WVD = filepath.Join(root, cfg.WVD)
}
if cfg.ModulesDir != "" && !filepath.IsAbs(cfg.ModulesDir) {
cfg.ModulesDir = filepath.Join(root, cfg.ModulesDir)
}
if cfg.ModulesSyncIntervalSec <= 0 {
cfg.ModulesSyncIntervalSec = 300
}
return cfg
}
func (c Config) ModulesSyncInterval() time.Duration {
if c.ModulesSyncIntervalSec <= 0 {
return 5 * time.Minute
}
return time.Duration(c.ModulesSyncIntervalSec) * time.Second
}

View file

@ -0,0 +1,121 @@
// Package modsync pushes local modules/<name>/module.yaml to streamd
// when the remote copy is missing or the SHA-256 differs.
package modsync
import (
"crypto/sha256"
"encoding/hex"
"log"
"os"
"path/filepath"
"strings"
"time"
"drmdecryption/apps/agent/internal/client"
"drmdecryption/modhost"
"drmdecryption/repo"
)
// Syncer compares local module.yaml files to streamd and PUTs updates.
type Syncer struct {
API *client.Client
ModulesDir string // empty = modhost.ModulesDir(repo.Root())
Interval time.Duration
Log *log.Logger
}
func (s *Syncer) modulesDir() string {
if strings.TrimSpace(s.ModulesDir) != "" {
return s.ModulesDir
}
return modhost.ModulesDir(repo.Root())
}
// Once uploads every local module.yaml that is missing or stale on streamd.
func (s *Syncer) Once() error {
dir := s.modulesDir()
ents, err := os.ReadDir(dir)
if err != nil {
if os.IsNotExist(err) {
s.logf("modules sync: no local dir %s", dir)
return nil
}
return err
}
remote, err := s.API.ListModules()
if err != nil {
return err
}
byName := make(map[string]client.ModuleInfo, len(remote))
for _, m := range remote {
byName[m.Name] = m
}
for _, e := range ents {
if !e.IsDir() || strings.HasPrefix(e.Name(), ".") {
continue
}
name := e.Name()
yamlPath := filepath.Join(dir, name, "module.yaml")
raw, err := os.ReadFile(yamlPath)
if err != nil {
if os.IsNotExist(err) {
continue
}
s.logf("modules sync: read %s: %v", yamlPath, err)
continue
}
sum := sha256.Sum256(raw)
localSHA := hex.EncodeToString(sum[:])
rm, ok := byName[name]
if ok && rm.HasYAML && strings.EqualFold(rm.YAMLSHA256, localSHA) {
continue
}
if err := s.API.PutModuleYAML(name, raw); err != nil {
s.logf("modules sync: PUT %s: %v", name, err)
continue
}
if !ok || !rm.HasYAML {
s.logf("modules sync: uploaded %s (new)", name)
} else {
s.logf("modules sync: updated %s", name)
}
}
return nil
}
// Loop runs Once immediately, then on Interval until stop closes.
func (s *Syncer) Loop(stop <-chan struct{}) {
interval := s.Interval
if interval <= 0 {
interval = 5 * time.Minute
}
_ = s.runLogged()
t := time.NewTicker(interval)
defer t.Stop()
for {
select {
case <-stop:
return
case <-t.C:
_ = s.runLogged()
}
}
}
func (s *Syncer) runLogged() error {
if err := s.Once(); err != nil {
s.logf("modules sync error: %v", err)
return err
}
return nil
}
func (s *Syncer) logf(format string, args ...any) {
if s.Log != nil {
s.Log.Printf(format, args...)
return
}
log.Printf(format, args...)
}