Read/write config files as UTF-8 on Windows (#4)

Path.read_text()/write_text() default to the platform encoding (cp1252
on Windows), which mangles or crashes on UTF-8 files. yt-dlp's
video.info.json is UTF-8 and routinely contains non-ASCII bytes, so on
Windows the parse raised UnicodeDecodeError, was swallowed by a bare
except, and the /watch report came back missing Title/Uploader.

- download.py: read video.info.json as UTF-8; log parse failures to
  stderr instead of swallowing them silently.
- whisper.py, setup.py: same UTF-8 fix on .env reads and writes for
  symmetry across platforms.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
bradautomates
2026-05-09 08:21:39 +10:00
parent 3c488688d1
commit 205af96c19
3 changed files with 9 additions and 8 deletions
+3 -2
View File
@@ -98,14 +98,15 @@ def download_url(url: str, out_dir: Path) -> dict:
info: dict = {}
if info_path.exists():
try:
raw = json.loads(info_path.read_text())
raw = json.loads(info_path.read_text(encoding="utf-8"))
info = {
"title": raw.get("title"),
"uploader": raw.get("uploader") or raw.get("channel"),
"duration": raw.get("duration"),
"url": raw.get("webpage_url") or url,
}
except Exception:
except Exception as exc:
print(f"[watch] info.json parse failed: {exc}", file=sys.stderr)
info = {"url": url}
return {