streamd: preview quality picker, dashboard polish, C4 wrap keys
- 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:
parent
b3955bd81e
commit
066e018749
113 changed files with 19002 additions and 1541 deletions
|
|
@ -131,18 +131,163 @@ def fetch_content_keys_raw(
|
|||
return keys
|
||||
|
||||
|
||||
_CHALLENGE_KEYS = (
|
||||
"request",
|
||||
"licenseRequest",
|
||||
"license_request",
|
||||
"widevineChallenge",
|
||||
"widevine_challenge",
|
||||
"challenge",
|
||||
"payload",
|
||||
"rawLicenseRequestBase64",
|
||||
"message",
|
||||
"drm_info",
|
||||
)
|
||||
|
||||
|
||||
def _replace_challenge(obj, challenge_b64: str, challenge_bytes: bytes) -> bool:
|
||||
"""Replace the Widevine challenge field inside a captured JSON license body."""
|
||||
if isinstance(obj, dict):
|
||||
for key in _CHALLENGE_KEYS:
|
||||
if key not in obj:
|
||||
continue
|
||||
val = obj[key]
|
||||
if key == "drm_info" and isinstance(val, list):
|
||||
obj[key] = list(challenge_bytes)
|
||||
return True
|
||||
if isinstance(val, str) and len(val) >= 8:
|
||||
obj[key] = challenge_b64
|
||||
return True
|
||||
if isinstance(val, dict) and _replace_challenge(val, challenge_b64, challenge_bytes):
|
||||
return True
|
||||
for val in obj.values():
|
||||
if _replace_challenge(val, challenge_b64, challenge_bytes):
|
||||
return True
|
||||
elif isinstance(obj, list):
|
||||
for item in obj:
|
||||
if _replace_challenge(item, challenge_b64, challenge_bytes):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _license_bytes_from_response(response: requests.Response) -> bytes:
|
||||
body = response.content
|
||||
if not body:
|
||||
raise RuntimeError("empty license response body")
|
||||
# Prefer JSON wrappers used by RedBee / ModularDrm-style proxies.
|
||||
try:
|
||||
data = response.json()
|
||||
except Exception:
|
||||
data = None
|
||||
if isinstance(data, dict):
|
||||
for path in (
|
||||
("license",),
|
||||
("licenseResponse",),
|
||||
("license_response",),
|
||||
("payload",),
|
||||
("message",),
|
||||
("getWidevineLicenseResponse", "license"),
|
||||
("status", "license"),
|
||||
):
|
||||
cur: object = data
|
||||
ok = True
|
||||
for key in path:
|
||||
if not isinstance(cur, dict) or key not in cur:
|
||||
ok = False
|
||||
break
|
||||
cur = cur[key]
|
||||
if ok and isinstance(cur, str) and cur:
|
||||
try:
|
||||
return base64.b64decode(cur)
|
||||
except Exception:
|
||||
return cur.encode("utf-8")
|
||||
# Some LSP responses nest the blob under status.success payload.
|
||||
if data.get("status", {}).get("success") is False:
|
||||
raise RuntimeError("license LSP error: " + json.dumps(data)[:500])
|
||||
return body
|
||||
|
||||
|
||||
def fetch_content_keys_wrap(
|
||||
*,
|
||||
wvd: Path,
|
||||
pssh_b64: str,
|
||||
license_url: str,
|
||||
wrap_json: str,
|
||||
user_agent: str,
|
||||
) -> list[str]:
|
||||
"""Re-POST a captured JSON license body with a fresh local CDM challenge.
|
||||
|
||||
Used by Channel 4 / RedBee (wvlicenceproxy-service) which reject raw
|
||||
octet-stream (HTTP 415) and need the phone's token fields intact.
|
||||
"""
|
||||
try:
|
||||
template = json.loads(wrap_json)
|
||||
except Exception as exc:
|
||||
raise RuntimeError(f"wrap-json is not valid JSON: {exc}") from exc
|
||||
|
||||
device = Device.load(str(wvd))
|
||||
cdm = Cdm.from_device(device)
|
||||
session_id = cdm.open()
|
||||
try:
|
||||
challenge = cdm.get_license_challenge(session_id, PSSH(pssh_b64))
|
||||
challenge_b64 = base64.b64encode(challenge).decode("utf-8")
|
||||
if not _replace_challenge(template, challenge_b64, challenge):
|
||||
raise RuntimeError(
|
||||
"wrap-json has no recognisable challenge field "
|
||||
f"(tried {', '.join(_CHALLENGE_KEYS)})"
|
||||
)
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json, */*",
|
||||
}
|
||||
if user_agent:
|
||||
headers["User-Agent"] = user_agent
|
||||
response = requests.post(
|
||||
license_url, json=template, headers=headers, timeout=30
|
||||
)
|
||||
if response.status_code >= 400:
|
||||
raise RuntimeError(
|
||||
f"license HTTP {response.status_code}: {response.text[:500]!r}"
|
||||
)
|
||||
license_bytes = _license_bytes_from_response(response)
|
||||
try:
|
||||
cdm.parse_license(session_id, license_bytes)
|
||||
except Exception:
|
||||
try:
|
||||
cdm.parse_license(session_id, base64.b64decode(license_bytes))
|
||||
except Exception as exc:
|
||||
raise RuntimeError(
|
||||
f"parse_license failed ({len(license_bytes)} bytes): {exc}"
|
||||
) from exc
|
||||
keys = [
|
||||
f"{key.kid.hex}:{key.key.hex()}"
|
||||
for key in cdm.get_keys(session_id)
|
||||
if key.type == "CONTENT"
|
||||
]
|
||||
finally:
|
||||
cdm.close(session_id)
|
||||
if not keys:
|
||||
raise RuntimeError("no CONTENT keys")
|
||||
return keys
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
p = argparse.ArgumentParser(description="Widevine CDM helper → KID:KEY")
|
||||
p.add_argument("--wvd", type=Path, required=True, help="Path to .wvd device file")
|
||||
p.add_argument("--pssh", required=True, help="Base64 PSSH box")
|
||||
p.add_argument(
|
||||
"--mode",
|
||||
choices=("modulardrm", "raw"),
|
||||
choices=("modulardrm", "raw", "wrap"),
|
||||
default="modulardrm",
|
||||
help="modulardrm=RTE JSON; raw=Brightcove/octet-stream challenge",
|
||||
help="modulardrm=RTE JSON; raw=octet-stream; wrap=captured JSON body",
|
||||
)
|
||||
p.add_argument("--auth", default="", help="Authorization header (modulardrm)")
|
||||
p.add_argument("--pid", default="", help="releasePid (modulardrm)")
|
||||
p.add_argument(
|
||||
"--wrap-json",
|
||||
default="",
|
||||
help="Captured phone license POST JSON (wrap mode)",
|
||||
)
|
||||
p.add_argument(
|
||||
"--license-url",
|
||||
required=True,
|
||||
|
|
@ -177,6 +322,21 @@ def main(argv: list[str] | None = None) -> int:
|
|||
license_url=args.license_url,
|
||||
user_agent=args.user_agent,
|
||||
)
|
||||
elif args.mode == "wrap":
|
||||
if not args.wrap_json.strip():
|
||||
print(
|
||||
"[!] --wrap-json required for wrap mode "
|
||||
"(phone must complete a license POST during capture)",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 2
|
||||
keys = fetch_content_keys_wrap(
|
||||
wvd=args.wvd,
|
||||
pssh_b64=args.pssh,
|
||||
license_url=args.license_url,
|
||||
wrap_json=args.wrap_json,
|
||||
user_agent=args.user_agent,
|
||||
)
|
||||
else:
|
||||
if not args.auth or not args.pid:
|
||||
print("[!] --auth and --pid required for modulardrm mode", file=sys.stderr)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue