Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix(youtube): fall back through en,es,pt transcripts via LAST30DAYS_YT_SUB_LANGS (fixes #469) (#486)

SAI MOHANEESH9a59d88b110e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aed9a4b9..8ca3f967 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- YouTube transcript extraction now falls back through `en,es,pt` (configurable via `LAST30DAYS_YT_SUB_LANGS`) instead of English-only, so non-English videos with auto-captions in any of those three languages now contribute transcripts to the brief ([#469](https://github.com/mvanhorn/last30days-skill/issues/469))
- Keyless Reddit comment enrichment now spends its limited slots on entity-matching posts first (mirroring rerank's entity-miss demotion signal) instead of raw upvote order, so off-topic high-upvote threads from broad subreddits no longer consume the comment budget only to be demoted afterward ([#484](https://github.com/mvanhorn/last30days-skill/pull/484))
## [3.3.1] - 2026-05-30
diff --git a/skills/last30days/scripts/lib/env.py b/skills/last30days/scripts/lib/env.py
index 93340f1d..a5c54f89 100644
--- a/skills/last30days/scripts/lib/env.py
+++ b/skills/last30days/scripts/lib/env.py
@@ -415,6 +415,7 @@ def get_config() -> dict[str, Any]:
('EXCLUDE_SOURCES', ''),
('LAST30DAYS_YOUTUBE_SSH_HOST', None),
('LAST30DAYS_TRANSCRIPT_TIMEOUT', None),
+ ('LAST30DAYS_YT_SUB_LANGS', 'en,es,pt'),
]
for key, default in keys:
diff --git a/skills/last30days/scripts/lib/youtube_yt.py b/skills/last30days/scripts/lib/youtube_yt.py
index 3340e0a2..2adbb0a8 100644
--- a/skills/last30days/scripts/lib/youtube_yt.py
+++ b/skills/last30days/scripts/lib/youtube_yt.py
@@ -531,6 +531,30 @@ def _fetch_transcript_direct(
return vtt_text
+def _ytdlp_sub_langs() -> str:
+ """Caption languages to try, from LAST30DAYS_YT_SUB_LANGS (default en,es,pt)."""
+ raw = os.environ.get("LAST30DAYS_YT_SUB_LANGS", "").strip()
+ if not raw:
+ return "en,es,pt"
+ return ",".join(code.strip().lower() for code in raw.split(",") if code.strip()) or "en,es,pt"
+
+
+def _pick_ytdlp_vtt(video_id: str, temp_dir: str, priority: List[str]) -> Optional[Path]:
+ """Return the best on-disk VTT match for video_id, preferring priority order."""
+ matches = list(Path(temp_dir).glob(f"{video_id}*.vtt"))
+ if not matches:
+ return None
+ priority_index = {code: i for i, code in enumerate(priority)}
+
+ def rank(p: Path) -> int:
+ stem = p.stem
+ suffix = stem[len(video_id) + 1:] if stem.startswith(video_id + ".") else ""
+ code = suffix.split("-")[0].split(".")[0]
+ return priority_index.get(code, len(priority_index))
+
+ return sorted(matches, key=rank)[0]
+
+
def _transcript_backoff(video_id: str, attempt: int) -> float:
"""Backoff seconds before a transcript retry.
@@ -543,14 +567,9 @@ def _transcript_backoff(video_id: str, attempt: int) -> float:
def _read_vtt(video_id: str, temp_dir: str) -> Optional[str]:
"""Return the VTT text yt-dlp wrote for ``video_id``, or None if absent."""
- # yt-dlp may save as .en.vtt or an en variant like .en-orig.vtt
- vtt_path = Path(temp_dir) / f"{video_id}.en.vtt"
- if not vtt_path.exists():
- for p in Path(temp_dir).glob(f"{video_id}*.vtt"):
- vtt_path = p
- break
- else:
- return None
+ vtt_path = _pick_ytdlp_vtt(video_id, temp_dir, _ytdlp_sub_langs().split(","))
+ if vtt_path is None:
+ return None
try:
return vtt_path.read_text(encoding="utf-8", errors="replace")
@@ -583,7 +602,7 @@ def _fetch_transcript_ytdlp(
"--ignore-config",
"--no-cookies-from-browser",
"--write-auto-subs",
- "--sub-lang", "en",
+ "--sub-lang", _ytdlp_sub_langs(),
"--sub-format", "vtt",
"--skip-download",
"--no-warnings",
diff --git a/tests/test_youtube_yt.py b/tests/test_youtube_yt.py
index de87ce34..f9d7fd91 100644
--- a/tests/test_youtube_yt.py
+++ b/tests/test_youtube_yt.py
@@ -6,6 +6,7 @@ import tempfile
import unittest
import urllib.error
from datetime import datetime, timedelta, timezone
+from pathlib import Path
from unittest import mock
from lib import youtube_yt
@@ -85,6 +86,115 @@ class TestYtDlpFlags(unittest.TestCase):
self.assertIn("--no-cookies-from-browser", cmd)
+class TestYtDlpSubLangs(unittest.TestCase):
+ """Verify LAST30DAYS_YT_SUB_LANGS knob and language-agnostic VTT matching."""
+
+ def _fake_result(self, stdout: str = "", returncode: int = 0):
+ from lib.subproc import SubprocResult
+ return SubprocResult(returncode=returncode, stdout=stdout, stderr="")
+
+ def test_default_sub_langs_when_env_unset(self):
+ """When LAST30DAYS_YT_SUB_LANGS is not set, the default is en,es,pt."""
+ with mock.patch.dict(os.environ, {}, clear=False):
+ os.environ.pop("LAST30DAYS_YT_SUB_LANGS", None)
+ self.assertEqual(youtube_yt._ytdlp_sub_langs(), "en,es,pt")
+
+ def test_env_var_overrides_default(self):
+ with mock.patch.dict(os.environ, {"LAST30DAYS_YT_SUB_LANGS": "fr,de"}):
+ self.assertEqual(youtube_yt._ytdlp_sub_langs(), "fr,de")
+
+ def test_env_var_normalizes_whitespace_and_case(self):
+ with mock.patch.dict(os.environ, {"LAST30DAYS_YT_SUB_LANGS": " EN , Es , PT "}):
+ self.assertEqual(youtube_yt._ytdlp_sub_langs(), "en,es,pt")
+
+ def test_env_var_handles_empty_segments(self):
+ with mock.patch.dict(os.environ, {"LAST30DAYS_YT_SUB_LANGS": "en,,pt,"}):
+ self.assertEqual(youtube_yt._ytdlp_sub_langs(), "en,pt")
+
+ def test_env_var_empty_string_falls_back_to_default(self):
+ with mock.patch.dict(os.environ, {"LAST30DAYS_YT_SUB_LANGS": " "}):
+ self.assertEqual(youtube_yt._ytdlp_sub_langs(), "en,es,pt")
+
+ def test_transcript_cmd_uses_default_sub_langs(self):
+ """Regression: the --sub-lang arg is en,es,pt by default (issue #469)."""
+ with tempfile.TemporaryDirectory() as temp_dir, \
+ mock.patch.dict(os.environ, {}, clear=False), \
+ mock.patch.object(youtube_yt, "is_ytdlp_installed", return_value=True), \
+ mock.patch.object(youtube_yt.subproc, "run_with_timeout", return_value=self._fake_result()) as run_mock:
+ os.environ.pop("LAST30DAYS_YT_SUB_LANGS", None)
+ youtube_yt.fetch_transcript("abc123", temp_dir)
+
+ cmd = run_mock.call_args_list[0].args[0]
+ idx = cmd.index("--sub-lang")
+ self.assertEqual(cmd[idx + 1], "en,es,pt")
+
+ def test_transcript_cmd_respects_env_var_override(self):
+ with tempfile.TemporaryDirectory() as temp_dir, \
+ mock.patch.dict(os.environ, {"LAST30DAYS_YT_SUB_LANGS": "fr,de,it"}), \
+ mock.patch.object(youtube_yt, "is_ytdlp_installed", return_value=True), \
+ mock.patch.object(youtube_yt.subproc, "run_with_timeout", return_value=self._fake_result()) as run_mock:
+ youtube_yt.fetch_transcript("abc123", temp_dir)
+
+ cmd = run_mock.call_args_list[0].args[0]
+ idx = cmd.index("--sub-lang")
+ self.assertEqual(cmd[idx + 1], "fr,de,it")
+
+ def test_vtt_matching_picks_non_english_track(self):
+ """When yt-dlp writes a Spanish track (no English available), we read it."""
+ with tempfile.TemporaryDirectory() as temp_dir:
+ # Simulate yt-dlp output: only a Spanish VTT is available
+ (Path(temp_dir) / "abc123.es.vtt").write_text(
+ "WEBVTT\n\n00:00:00.000 --> 00:00:02.000\nHola mundo esta es una prueba.\n",
+ encoding="utf-8",
+ )
+ with mock.patch.object(youtube_yt, "is_ytdlp_installed", return_value=True), \
+ mock.patch.object(youtube_yt.subproc, "run_with_timeout", return_value=self._fake_result()):
+ vtt = youtube_yt._fetch_transcript_ytdlp("abc123", temp_dir)
+
+ self.assertIsNotNone(vtt)
+ self.assertIn("Hola mundo", vtt)
+
+ def test_vtt_matching_respects_non_default_priority(self):
+ """When multiple tracks exist, the user-requested priority wins
+ over alphabetical order (regression for the Greptile review on #486)."""
+ with tempfile.TemporaryDirectory() as temp_dir:
+ (Path(temp_dir) / "abc123.en.vtt").write_text(
+ "WEBVTT\n\n00:00:00.000 --> 00:00:02.000\nEnglish first track.\n",
+ encoding="utf-8",
+ )
+ (Path(temp_dir) / "abc123.es.vtt").write_text(
+ "WEBVTT\n\n00:00:00.000 --> 00:00:02.000\nSpanish second track.\n",
+ encoding="utf-8",
+ )
+ with mock.patch.dict(os.environ, {"LAST30DAYS_YT_SUB_LANGS": "es,en"}), \
+ mock.patch.object(youtube_yt, "is_ytdlp_installed", return_value=True), \
+ mock.patch.object(youtube_yt.subproc, "run_with_timeout", return_value=self._fake_result()):
+ vtt = youtube_yt._fetch_transcript_ytdlp("abc123", temp_dir)
+
+ self.assertIsNotNone(vtt)
+ self.assertIn("Spanish", vtt)
+
+ def test_vtt_matching_unknown_suffix_sorts_last(self):
+ """A non-lang suffix (e.g. a stray .tmp or .live_chat) must not
+ win over a real track that just happens to be alphabetically later."""
+ with tempfile.TemporaryDirectory() as temp_dir:
+ (Path(temp_dir) / "abc123.zz.vtt").write_text(
+ "WEBVTT\n\n00:00:00.000 --> 00:00:02.000\nZZ track content.\n",
+ encoding="utf-8",
+ )
+ (Path(temp_dir) / "abc123.es.vtt").write_text(
+ "WEBVTT\n\n00:00:00.000 --> 00:00:02.000\nSpanish content.\n",
+ encoding="utf-8",
+ )
+ with mock.patch.dict(os.environ, {"LAST30DAYS_YT_SUB_LANGS": "es,en,pt"}), \
+ mock.patch.object(youtube_yt, "is_ytdlp_installed", return_value=True), \
+ mock.patch.object(youtube_yt.subproc, "run_with_timeout", return_value=self._fake_result()):
+ vtt = youtube_yt._fetch_transcript_ytdlp("abc123", temp_dir)
+
+ self.assertIsNotNone(vtt)
+ self.assertIn("Spanish", vtt)
+
+
class TestExtractTranscriptHighlights(unittest.TestCase):
def test_extracts_specific_sentences(self):
transcript = (