feat(logging): expand debug-logging coverage, add primitives, redaction & tests

Instrument the full download pipeline in the structured JSONL debug logger and make adding logging to new features a one-liner.

Coverage:
- DRM license request/response, content keys (incl. remote-CDM seam) and decrypt timing across Widevine/PlayReady/ClearKey
- DASH/HLS/ISM manifest fetch + parse milestones (HLS.to_tracks also covers the m3u8_parser path used by iTunes/ATV-style services)
- Per-backend vault get/add via the Vaults manager, track selection, subtitle conversion, repackage, normalize_vui, and full mkvmerge mux (command, duration, output size, warnings)
- All external tooling (ffmpeg, ffprobe, mkvmerge, mkvpropedit, dovi_tool, SubtitleEdit, ccextractor) via a unified `tool_run` op, centralised in run_step/ffprobe + log_tool_run

DX:
- Add log_event() / timed_operation() primitives (no-op when disabled); retrofit ~91 guard/timing blocks onto them
- Fix message= collision in log_drm_operation/log_vault_query/log_service_call that raised TypeError on the live decrypt path

Redaction (redact_all = redact_text -> redact_url -> redact_path):
- Collapse content/CDN/api URLs to `redacted[.ext]`
- Strip local path prefixes (install root -> <unshackle>, venv -> <venv>, home -> ~)
- Apply to every logged string so shared logs leak no URLs, paths or usernames
- Drop per-request service_call logging (manifest parse is the request seam)
This commit is contained in:
imSp4rky
2026-06-09 22:12:05 -06:00
parent 7064d261c2
commit 394ed67e28
24 changed files with 1763 additions and 793 deletions
+45 -1
View File
@@ -4,6 +4,7 @@ import logging
import math
import re
import subprocess
import time
from enum import Enum
from pathlib import Path
from typing import Any, Optional, Union
@@ -14,7 +15,8 @@ from unshackle.core import binaries
from unshackle.core.config import config
from unshackle.core.tracks.subtitle import Subtitle
from unshackle.core.tracks.track import Track
from unshackle.core.utilities import FPS, get_boxes
from unshackle.core.utilities import FPS, get_boxes, log_event
from unshackle.core.utils.subprocess import log_tool_run
class Video(Track):
@@ -379,6 +381,7 @@ class Video(Track):
original_path = self.path
output_path = original_path.with_stem(f"{original_path.stem}_{['limited', 'full'][range_]}_range")
range_start = time.monotonic()
subprocess.run(
[
binaries.FFMPEG,
@@ -395,6 +398,14 @@ class Video(Track):
],
check=True,
)
log_tool_run(
"ffmpeg change range",
"ffmpeg",
0,
duration_ms=round((time.monotonic() - range_start) * 1000, 1),
codec=str(self.codec),
full_range=bool(range_),
)
self.path = output_path
original_path.unlink()
@@ -458,6 +469,18 @@ class Video(Track):
self.path = output_path
original_path.unlink()
log_event(
"normalize_vui",
level="DEBUG",
message=f"Rewrote {self.codec} VUI colour metadata to match {self.range}",
context={
"codec": str(self.codec),
"range": str(self.range),
"vui": {"primaries": primaries, "transfer": transfer, "matrix": matrix},
"id": self.id,
},
)
return True
def ccextractor(
@@ -473,6 +496,7 @@ class Video(Track):
out_path = Path(out_path)
def _run_ccextractor() -> bool:
cc_start = time.monotonic()
try:
subprocess.run(
[binaries.CCExtractor, "-trim", "-nobom", "-noru", "-ru1", "-o", out_path, self.path],
@@ -482,8 +506,21 @@ class Video(Track):
)
except subprocess.CalledProcessError as e:
out_path.unlink(missing_ok=True)
log_tool_run(
"ccextractor",
"ccextractor",
e.returncode,
duration_ms=round((time.monotonic() - cc_start) * 1000, 1),
)
if e.returncode != 10: # 10 = No captions found
raise
return out_path.exists()
log_tool_run(
"ccextractor",
"ccextractor",
0,
duration_ms=round((time.monotonic() - cc_start) * 1000, 1),
)
return out_path.exists()
# Try on the original file first (preserves container-level CC data like c608 boxes),
@@ -578,6 +615,7 @@ class Video(Track):
original_path = self.path
cleaned_path = original_path.with_suffix(f".cleaned{original_path.suffix}")
eia_start = time.monotonic()
subprocess.run(
[
binaries.FFMPEG,
@@ -598,6 +636,12 @@ class Video(Track):
],
check=True,
)
log_tool_run(
"ffmpeg remove EIA-CC",
"ffmpeg",
0,
duration_ms=round((time.monotonic() - eia_start) * 1000, 1),
)
log.info(" + Removed")