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:
404errordeveloper 2026-10-06 00:25:35 +02:00
commit 2fa8f2435f
121 changed files with 17802 additions and 0 deletions

101
apps/pkg/session/session.go Normal file
View file

@ -0,0 +1,101 @@
package session
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
// Session is the on-disk capture result (shared with restream tooling).
type Session struct {
App string `json:"app"`
Channel string `json:"channel,omitempty"`
CapturedAt string `json:"captured_at"`
PSSH string `json:"pssh,omitempty"`
Auth string `json:"auth,omitempty"`
PID string `json:"pid,omitempty"`
Key string `json:"key,omitempty"`
KID string `json:"kid,omitempty"`
KeyHex string `json:"key_hex,omitempty"`
MPD string `json:"mpd,omitempty"`
LicenseURL string `json:"license_url,omitempty"`
}
// Write creates outputs/<app>/<stamp>/session.json (+ field txt files + latest).
func Write(root, app string, s Session) (string, error) {
stamp := time.Now().Format("20060102-150405")
dir := filepath.Join(root, "outputs", app, stamp)
if err := os.MkdirAll(dir, 0o755); err != nil {
return "", err
}
s.App = app
if s.CapturedAt == "" {
s.CapturedAt = time.Now().Format(time.RFC3339)
}
if s.Key != "" && s.KID == "" {
parts := strings.SplitN(s.Key, ":", 2)
if len(parts) == 2 {
s.KID = parts[0]
s.KeyHex = parts[1]
}
}
raw, err := json.MarshalIndent(s, "", " ")
if err != nil {
return "", err
}
path := filepath.Join(dir, "session.json")
if err := os.WriteFile(path, append(raw, '\n'), 0o644); err != nil {
return "", err
}
fields := map[string]string{
"pssh": s.PSSH,
"auth": s.Auth,
"pid": s.PID,
"key": s.Key,
"mpd": s.MPD,
}
for name, val := range fields {
if val == "" {
continue
}
_ = os.WriteFile(filepath.Join(dir, name+".txt"), []byte(val+"\n"), 0o644)
}
latest := filepath.Join(root, "outputs", app, "latest")
_ = os.RemoveAll(latest)
// Best-effort directory copy for Windows (symlinks often need admin).
if err := copyDir(dir, latest); err != nil {
fmt.Fprintf(os.Stderr, "[!] latest link/copy: %v\n", err)
}
return path, nil
}
func copyDir(src, dst string) error {
if err := os.MkdirAll(dst, 0o755); err != nil {
return err
}
entries, err := os.ReadDir(src)
if err != nil {
return err
}
for _, e := range entries {
in := filepath.Join(src, e.Name())
out := filepath.Join(dst, e.Name())
if e.IsDir() {
if err := copyDir(in, out); err != nil {
return err
}
continue
}
b, err := os.ReadFile(in)
if err != nil {
return err
}
if err := os.WriteFile(out, b, 0o644); err != nil {
return err
}
}
return nil
}

View file

@ -0,0 +1,66 @@
package session
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"time"
)
// Stream is a streamd-ready description of one playable channel, as produced by
// a provider catalog lookup. MPD holds the manifest URL whatever its type.
type Stream struct {
Name string `json:"name"`
Title string `json:"title"`
App string `json:"app"`
Channel string `json:"channel"`
MPD string `json:"mpd"`
Key string `json:"key"`
Keys []string `json:"keys,omitempty"`
PSSH string `json:"pssh,omitempty"`
PrimaryKID string `json:"primary_kid,omitempty"`
HeadersJSON string `json:"headers_json"`
Rewriter string `json:"rewriter"`
LicenseURL string `json:"license_url,omitempty"`
AccountID string `json:"account_id,omitempty"`
VideoID string `json:"video_id,omitempty"`
PlaybackURL string `json:"playback_url,omitempty"`
ManifestType string `json:"manifest_type,omitempty"`
}
// WriteStream writes outputs/<app>/<stamp>/{session.json,mpd.txt,license.txt,…}
// and refreshes outputs/<app>/latest. The app name comes from the caller so no
// provider name is baked in here.
func WriteStream(root, app string, info Stream) (string, error) {
stamp := time.Now().Format("20060102-150405")
dir := filepath.Join(root, "outputs", app, stamp)
if err := os.MkdirAll(dir, 0o755); err != nil {
return "", err
}
raw, err := json.MarshalIndent(info, "", " ")
if err != nil {
return "", err
}
if err := os.WriteFile(filepath.Join(dir, "session.json"), append(raw, '\n'), 0o644); err != nil {
return "", err
}
write := func(name, val string) {
if val == "" {
return
}
_ = os.WriteFile(filepath.Join(dir, name), []byte(val+"\n"), 0o644)
}
write("mpd.txt", info.MPD)
write("license.txt", info.LicenseURL)
write("pssh.txt", info.PSSH)
write("key.txt", info.Key)
write("pid.txt", info.VideoID)
if len(info.Keys) > 0 {
write("keys.txt", strings.Join(info.Keys, "\n"))
}
latest := filepath.Join(root, "outputs", app, "latest")
_ = os.RemoveAll(latest)
_ = copyDir(dir, latest)
return dir, nil
}