Initial commit: Null DRM Official
Capture, decrypt, and restream toolkit with compiled-in app modules (RTE, TG4, BBC), on-device MITM proxy, streamd control plane, and www. BBC module.yaml is published (clear streams); other module values stay local.
This commit is contained in:
commit
2fa8f2435f
121 changed files with 17802 additions and 0 deletions
104
apps/agent/internal/config/config.go
Normal file
104
apps/agent/internal/config/config.go
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"drmdecryption/repo"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
StreamdURL string `yaml:"streamd_url"`
|
||||
Token string `yaml:"token"`
|
||||
PollIntervalSec int `yaml:"poll_interval_sec"`
|
||||
DataDir string `yaml:"data_dir"`
|
||||
Workers int `yaml:"workers"`
|
||||
MaxAttempts int `yaml:"max_attempts"`
|
||||
CaptureWaitSec int `yaml:"capture_wait_sec"`
|
||||
Devices []string `yaml:"devices"`
|
||||
Python string `yaml:"python"`
|
||||
WVD string `yaml:"wvd"` // path to .wvd device file (required for key fetch)
|
||||
UserAgent string `yaml:"user_agent"`
|
||||
AgentID string `yaml:"agent_id"`
|
||||
}
|
||||
|
||||
func (c Config) PollInterval() time.Duration {
|
||||
if c.PollIntervalSec <= 0 {
|
||||
return 30 * time.Second
|
||||
}
|
||||
return time.Duration(c.PollIntervalSec) * time.Second
|
||||
}
|
||||
|
||||
func (c Config) CaptureWait() time.Duration {
|
||||
if c.CaptureWaitSec <= 0 {
|
||||
return 180 * time.Second
|
||||
}
|
||||
return time.Duration(c.CaptureWaitSec) * time.Second
|
||||
}
|
||||
|
||||
func Load(path string) (Config, error) {
|
||||
root := repo.Root()
|
||||
if path == "" {
|
||||
path = filepath.Join(root, "apps", "agent", "agent.yaml")
|
||||
}
|
||||
var cfg Config
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
cfg = defaults(root)
|
||||
return cfg, nil
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
if err := yaml.Unmarshal(raw, &cfg); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
cfg = applyDefaults(cfg, root)
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func defaults(root string) Config {
|
||||
return applyDefaults(Config{}, root)
|
||||
}
|
||||
|
||||
func applyDefaults(cfg Config, root string) Config {
|
||||
if cfg.StreamdURL == "" {
|
||||
cfg.StreamdURL = "http://127.0.0.1:8083"
|
||||
}
|
||||
if cfg.Token == "" {
|
||||
cfg.Token = os.Getenv("STREAMD_TOKEN")
|
||||
}
|
||||
if cfg.PollIntervalSec <= 0 {
|
||||
cfg.PollIntervalSec = 30
|
||||
}
|
||||
if cfg.DataDir == "" {
|
||||
cfg.DataDir = filepath.Join(root, ".cache", "agent")
|
||||
} else if !filepath.IsAbs(cfg.DataDir) {
|
||||
cfg.DataDir = filepath.Join(root, cfg.DataDir)
|
||||
}
|
||||
if cfg.Workers <= 0 {
|
||||
cfg.Workers = 1
|
||||
}
|
||||
if cfg.MaxAttempts <= 0 {
|
||||
cfg.MaxAttempts = 5
|
||||
}
|
||||
if cfg.CaptureWaitSec <= 0 {
|
||||
cfg.CaptureWaitSec = 180
|
||||
}
|
||||
if cfg.AgentID == "" {
|
||||
// Stable across restarts so the same agent can reclaim after a crash.
|
||||
// Override in apps/agent/agent.yaml when running multiple agents.
|
||||
host, _ := os.Hostname()
|
||||
if host == "" {
|
||||
host = "agent"
|
||||
}
|
||||
cfg.AgentID = host
|
||||
}
|
||||
if cfg.WVD != "" && !filepath.IsAbs(cfg.WVD) {
|
||||
cfg.WVD = filepath.Join(root, cfg.WVD)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue