Skip to content

Give your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.

fix(transcribe): decode subprocess output as UTF-8

lukiod68a0f442ef6d
diff --git a/agent_reach/transcribe.py b/agent_reach/transcribe.py
index 248a49da..e7a0c6c4 100644
--- a/agent_reach/transcribe.py
+++ b/agent_reach/transcribe.py
@@ -107,7 +107,8 @@ def _probe_audio_duration(path: Path) -> float:
proc = subprocess.run(
cmd,
capture_output=True,
- text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=FFPROBE_TIMEOUT_SECONDS,
)
except subprocess.TimeoutExpired:
@@ -158,7 +159,13 @@ def _run(cmd: List[str], timeout: int = 600) -> None:
network read or a hung probe must not block the CLI forever.
"""
try:
- proc = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
+ proc = subprocess.run(
+ cmd,
+ capture_output=True,
+ encoding="utf-8",
+ errors="replace",
+ timeout=timeout,
+ )
except subprocess.TimeoutExpired:
raise TranscribeError(f"{cmd[0]} timed out after {timeout}s")
if proc.returncode != 0:
diff --git a/tests/test_transcribe.py b/tests/test_transcribe.py
index f5524d33..4c2d6ba2 100644
--- a/tests/test_transcribe.py
+++ b/tests/test_transcribe.py
@@ -828,6 +828,37 @@ class TestMediaGenerationBudget:
)
+# --- Subprocess output decoding ---------------------------------------- #
+
+
+class TestSubprocessDecoding:
+ CJK_BYTES = "中文标题".encode("utf-8")
+
+ def _decoding_run(self, returncode: int):
+ def fake_run(cmd, **kwargs):
+ encoding = kwargs.get("encoding") or "gbk"
+ errors = kwargs.get("errors") or "strict"
+ text = self.CJK_BYTES.decode(encoding, errors)
+ return subprocess.CompletedProcess(cmd, returncode, text, text)
+
+ return fake_run
+
+ def test_run_preserves_cjk_failure_as_transcribe_error(self, monkeypatch):
+ monkeypatch.setattr(tr.subprocess, "run", self._decoding_run(1))
+
+ with pytest.raises(tr.TranscribeError, match="yt-dlp"):
+ tr._run(["yt-dlp", "https://example.com/video"], timeout=5)
+
+ def test_probe_preserves_cjk_failure_as_transcribe_error(
+ self, monkeypatch, tmp_path
+ ):
+ monkeypatch.setattr(tr, "_require", lambda _binary: None)
+ monkeypatch.setattr(tr.subprocess, "run", self._decoding_run(1))
+
+ with pytest.raises(tr.TranscribeError, match="duration"):
+ tr._probe_audio_duration(tmp_path / "audio.m4a")
+
+
# --- YouTubeChannel integration --------------------------------------- #