streamd: preview quality picker, dashboard polish, C4 wrap keys
All checks were successful
release / build-and-upload (push) Successful in 6m18s
modules-release / build-and-upload (push) Successful in 5m18s

- Preview player can select FHD/HD/SD (or ABR master) from publish links
- Embed dashboard screenshots in README; Linux streamd+agent setup guide
- C4 Widevine wrap license mode + require --wvd; prefer Widevine PSSH
- Channel 4 and My5 modules; streamd auth, variants, schedules, HLS gate
This commit is contained in:
404errordeveloper 2026-10-09 20:57:43 +02:00
parent b3955bd81e
commit 066e018749
113 changed files with 19002 additions and 1541 deletions

View file

@ -199,6 +199,9 @@ func Run(opt Options) (res Result, err error) {
proxyBin, caHash := resolveProxy(a, root)
hints := a.CaptureHints()
if chHints, ok := a.(app.ChannelCaptureHints); ok && strings.TrimSpace(opt.Channel) != "" {
hints = chHints.CaptureHintsFor(opt.Channel)
}
useTProxy := false
if tm, ok := a.(app.TransparentMITM); ok && tm.UseTransparentMITM() {
useTProxy = true
@ -253,6 +256,9 @@ func Run(opt Options) (res Result, err error) {
}
localLog := filepath.Join(root, ".cache", "appproxy-"+sanitize(serialTag)+".log")
localCap := filepath.Join(root, ".cache", "appproxy-"+sanitize(serialTag)+"_cap.json")
// Fresh local mirrors each run so grab-all does not reuse a prior channel's MPD.
_ = os.WriteFile(localLog, nil, 0o644)
_ = os.Remove(localCap)
stop := make(chan struct{})
go capture.MirrorLogLoop(c, hints.RemoteLog, localLog, stop)
defer close(stop)
@ -273,13 +279,28 @@ func Run(opt Options) (res Result, err error) {
keyMode = strings.ToLower(strings.TrimSpace(a.KeyMode()))
}
// Brightcove/HLS: proxy often captures license + master URL but not PSSH.
// C4 MPDs list PlayReady before Widevine — replace a PlayReady blob.
// Skip for clear/MPD-only apps (KeyMode none).
if keyMode != "none" && keyMode != "clear" {
if strings.TrimSpace(capData.Get("pssh")) == "" && strings.TrimSpace(capData.Get("mpd")) != "" {
if pssh, err := extractHLSPSSH(capData.Get("mpd")); err == nil && pssh != "" {
capData["pssh"] = pssh
} else if err != nil {
fmt.Fprintf(os.Stderr, "[!] HLS PSSH extract: %v\n", err)
mpdForPSSH := strings.TrimSpace(capData.Get("mpd"))
curPSSH := strings.TrimSpace(capData.Get("pssh"))
needPSSH := curPSSH == "" || isPlayReadyPSSH(curPSSH)
if needPSSH && mpdForPSSH != "" {
if strings.Contains(strings.ToLower(mpdForPSSH), ".mpd") {
if pssh, err := extractWidevinePSSHFromMPD(mpdForPSSH); err == nil && pssh != "" {
if curPSSH != "" && curPSSH != pssh {
fmt.Println("[*] Replaced PlayReady/non-Widevine PSSH with Widevine from MPD")
}
capData["pssh"] = pssh
} else if err != nil && curPSSH == "" {
fmt.Fprintf(os.Stderr, "[!] MPD Widevine PSSH extract: %v\n", err)
}
} else if curPSSH == "" {
if pssh, err := extractHLSPSSH(mpdForPSSH); err == nil && pssh != "" {
capData["pssh"] = pssh
} else if err != nil {
fmt.Fprintf(os.Stderr, "[!] HLS PSSH extract: %v\n", err)
}
}
}
}
@ -296,7 +317,7 @@ func Run(opt Options) (res Result, err error) {
fmt.Println("=========================")
fmt.Println()
fmt.Println("[+] Capture:")
for _, k := range []string{"pid", "mpd", "license_url", "auth", "pssh"} {
for _, k := range []string{"pid", "mpd", "license_url", "auth", "pssh", "license_body"} {
v := capData.Get(k)
if k == "license_url" {
v = first(v, licenseURL)
@ -305,8 +326,12 @@ func Run(opt Options) (res Result, err error) {
continue
}
label := k
if k == "license_url" {
switch k {
case "license_url":
label = "license"
case "license_body":
label = "license_body"
v = trim(v, 80) + fmt.Sprintf(" (%d bytes)", len(capData.Get("license_body")))
}
fmt.Println(" ", label+":", trim(v, 120))
}
@ -318,19 +343,31 @@ func Run(opt Options) (res Result, err error) {
var kerr error
key, kerr = fetchKey(opt, root, capData, licenseURL)
if kerr != nil {
return res, kerr
// Allow MPD-only sessions when no .wvd was passed (grab-all / first pass),
// unless the app requires keys (e.g. c4).
softOK := strings.Contains(kerr.Error(), "requires --wvd")
if softOK {
if rw, ok := a.(app.RequireWVD); ok && rw.RequireWVD() {
return res, kerr
}
fmt.Fprintf(os.Stderr, "[!] %v — saving MPD-only session\n", kerr)
} else {
return res, kerr
}
} else {
fmt.Println("[+] key:", strings.ReplaceAll(key, "\n", " | "))
}
fmt.Println("[+] key:", strings.ReplaceAll(key, "\n", " | "))
}
sess := session.Session{
Channel: opt.Channel,
PSSH: capData.Get("pssh"),
Auth: capData.Get("auth"),
PID: capData.Get("pid"),
Key: key,
MPD: mpdURL,
LicenseURL: licenseURL,
Channel: opt.Channel,
PSSH: capData.Get("pssh"),
Auth: capData.Get("auth"),
PID: capData.Get("pid"),
Key: key,
MPD: mpdURL,
LicenseURL: licenseURL,
LicenseBody: capData.Get("license_body"),
}
path, err := session.Write(root, a.Name(), sess)
if err != nil {
@ -393,6 +430,7 @@ func fetchKey(opt Options, root string, cap capture.Data, licenseURL string) (st
PID: cap.Get("pid"),
LicenseURL: licenseURL,
UserAgent: opt.UserAgent,
WrapJSON: cap.Get("license_body"),
}
mode := strings.ToLower(strings.TrimSpace(opt.KeyMode))
if mode == "" || mode == "auto" {
@ -403,6 +441,11 @@ func fetchKey(opt Options, root string, cap capture.Data, licenseURL string) (st
}
}
}
// RedBee / wrapped JSON: if the phone posted a license body, prefer wrap
// even when the module still says raw (migration safety).
if mode == "raw" && strings.TrimSpace(wopt.WrapJSON) != "" {
mode = "wrap"
}
switch mode {
case "raw":
// Brightcove returns multiple CONTENT keys; NRE needs all of them.
@ -411,6 +454,12 @@ func fetchKey(opt Options, root string, cap capture.Data, licenseURL string) (st
return "", err
}
return strings.Join(keys, "\n"), nil
case "wrap":
keys, err := wvkey.FetchWrapAll(wopt)
if err != nil {
return "", err
}
return strings.Join(keys, "\n"), nil
default:
return wvkey.Fetch(wopt)
}
@ -453,6 +502,62 @@ func extractHLSPSSH(masterURL string) (string, error) {
return "", fmt.Errorf("no Widevine PSSH in HLS master")
}
// PlayReady system id fragment inside a base64 PSSH box.
const playReadyPSSHFrag = "AAAAAmgTweZhAQoarkuZb4IhflQ"
// Widevine system id fragment inside a base64 PSSH box.
const widevinePSSHFrag = "AAAAA7e+LqXnWSs6jyCfc1R0h7Q"
func isPlayReadyPSSH(b64 string) bool {
return strings.Contains(b64, playReadyPSSHFrag) && !strings.Contains(b64, widevinePSSHFrag)
}
func extractWidevinePSSHFromMPD(mpdURL string) (string, error) {
resp, err := http.Get(mpdURL)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", fmt.Errorf("HTTP %d", resp.StatusCode)
}
body, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
if err != nil {
return "", err
}
mpd := string(body)
lower := strings.ToLower(mpd)
const (
wvUUID = "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
openTag = "<cenc:pssh"
closeTag = "</cenc:pssh>"
)
searchFrom := 0
for {
i := strings.Index(lower[searchFrom:], openTag)
if i < 0 {
break
}
i += searchFrom
j := strings.Index(mpd[i:], ">")
k := strings.Index(lower[i:], closeTag)
if j < 0 || k < 0 || k <= j {
break
}
val := strings.TrimSpace(mpd[i+j+1 : i+k])
windowStart := i - 400
if windowStart < 0 {
windowStart = 0
}
window := lower[windowStart : i+j]
if strings.Contains(window, wvUUID) || strings.Contains(val, widevinePSSHFrag) {
return val, nil
}
searchFrom = i + k + len(closeTag)
}
return "", fmt.Errorf("no Widevine cenc:pssh in MPD")
}
func trim(s string, n int) string {
if len(s) <= n {
return s