Skip to content

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

feat(youtube): expose yt-dlp proxy configuration (#1276)

Bhumika Guraved5ff96423c3
diff --git a/CONFIGURATION.md b/CONFIGURATION.md
index 1abf70fd..0239bd84 100644
--- a/CONFIGURATION.md
+++ b/CONFIGURATION.md
@@ -186,6 +186,13 @@ python3 skills/last30days/scripts/last30days.py "MCP servers" \
**Reddit keyless pacing.** Unauthenticated reddit.com requests (site search, listing partials, shreddit) share one token bucket. The default is `1` request per second with a burst of 2, slow enough that engine fan-out does not trip HTTP 429 on a typical home IP. Set `LAST30DAYS_REDDIT_KEYLESS_RATE` to a float req/sec to trade wall-clock for coverage: higher finishes faster and loses more sub-requests to 429; lower is safer and slower. Invalid or non-positive values fall back to `1`. A 429'd search or listing sub-request is retried once after a short jittered pause, still through the limiter. Identical reddit.com requests within one command (subreddit listings, listing feeds, comment pages, which repeat across subqueries) are fetched once and memoized, so a typical four-subquery run issues roughly a quarter of the requests it used to. Comment enrichment covers 4 / 8 / 12 threads per subquery at quick / default / deep depth. This does not change ScrapeCreators routing (`LAST30DAYS_REDDIT_BACKEND` / `LAST30DAYS_REDDIT_SC_MIN_ITEMS`).
+**YouTube proxy.** Set `YOUTUBE_PROXY` (or the shorter alias `YT_PROXY`) to route all yt-dlp traffic through a proxy. Useful when YouTube is blocked in your region. Accepts any proxy URL that yt-dlp supports: `socks5://127.0.0.1:1080`, `http://proxy.example.com:3128`, etc. `YOUTUBE_PROXY` takes precedence over `YT_PROXY`. Only yt-dlp calls are routed through this proxy — other HTTP requests the skill makes (ScrapeCreators, OpenAI, etc.) are unaffected. To route all traffic, use the standard `HTTP_PROXY` / `HTTPS_PROXY` environment variables instead.
+
+```bash
+# In .env or environment
+YOUTUBE_PROXY=socks5://127.0.0.1:1080
+```
+
**YouTube transcript tuning.** `LAST30DAYS_YT_SUB_LANGS` controls the comma-separated caption-language priority passed to yt-dlp and defaults to `en,es,pt`. The ScrapeCreators transcript fallback tries at most the first three distinct languages in that order, with a shared 30-second deadline per video; it stops after the first usable transcript. `LAST30DAYS_YT_PLAYER_CLIENT` defaults to `android` so yt-dlp can pass YouTube's web bot-gate without cookies (search, transcripts, and comments); set it empty to disable. When `SCRAPECREATORS_API_KEY` is available, yt-dlp uses one fast attempt before the paid fallback; set `LAST30DAYS_YT_TRANSCRIPT_FAST_TIMEOUT` to the number of seconds allowed for that attempt when a throttled host needs longer than the 12-second default. A VTT completed before the timeout is reused rather than discarded. `LAST30DAYS_YT_SEARCH_TIMEOUT` sets the per-search yt-dlp deadline (default 120s). Comparison-mode fan-out also caps concurrent yt-dlp processes process-wide and caches identical searches within a run so redundant `ytsearch` calls do not self-throttle the same IP.
**YouTube search backfill.** With `SCRAPECREATORS_API_KEY` set, `LAST30DAYS_YT_SC_MIN_ITEMS` defaults to `3`: a yt-dlp search returning 0, 1, or 2 videos makes one ScrapeCreators search per stream attempt. Set `0` for the previous empty-only behavior, or another positive integer to change the floor. An invalid value behaves like `0`, so a typo does not increase paid usage. Each backfill can also fetch transcripts for up to 6 videos at default depth (up to 3 language requests per video); endpoint retries and optional comment enrichment can add calls. A later thin-source retry may run another backfill. Free results and their transcripts remain in the merged result. A clean thin result records backfill detail; actual yt-dlp or ScrapeCreators failures mark partial coverage if retry does not recover.
diff --git a/changelog.d/158.added.md b/changelog.d/158.added.md
new file mode 100644
index 00000000..926f7929
--- /dev/null
+++ b/changelog.d/158.added.md
@@ -0,0 +1 @@
+Add `YOUTUBE_PROXY` (alias `YT_PROXY`) env var: when set, passes `--proxy <url>` to all yt-dlp invocations in `youtube_yt.py` (`search_youtube` and `fetch_transcript`), routing only yt-dlp traffic through the proxy. Useful in regions where YouTube is blocked. Documented in CONFIGURATION.md under "YouTube proxy".
diff --git a/skills/last30days/scripts/last30days.py b/skills/last30days/scripts/last30days.py
index fedaeab9..b5dc2463 100644
--- a/skills/last30days/scripts/last30days.py
+++ b/skills/last30days/scripts/last30days.py
@@ -3328,6 +3328,12 @@ def _main(
# datacenter IPs (see lib/youtube_yt.py for details).
if config.get("LAST30DAYS_YOUTUBE_SSH_HOST") and "LAST30DAYS_YOUTUBE_SSH_HOST" not in os.environ:
os.environ["LAST30DAYS_YOUTUBE_SSH_HOST"] = config["LAST30DAYS_YOUTUBE_SSH_HOST"]
+ # Surface YOUTUBE_PROXY / YT_PROXY so youtube_yt can read them without a
+ # config dependency. Shell-set values take precedence over .env values.
+ if config.get("YOUTUBE_PROXY") and "YOUTUBE_PROXY" not in os.environ:
+ os.environ["YOUTUBE_PROXY"] = config["YOUTUBE_PROXY"]
+ if config.get("YT_PROXY") and "YT_PROXY" not in os.environ:
+ os.environ["YT_PROXY"] = config["YT_PROXY"]
if args.preflight:
requested_sources = resolve_requested_sources(args.search, config)
diff --git a/skills/last30days/scripts/lib/env.py b/skills/last30days/scripts/lib/env.py
index 6464a679..d02c0059 100644
--- a/skills/last30days/scripts/lib/env.py
+++ b/skills/last30days/scripts/lib/env.py
@@ -739,6 +739,10 @@ def get_config(policy: ConfigLoadPolicy | None = None) -> dict[str, Any]:
# follow-up command. New writes use LAST30DAYS_REGISTER=eli5.
('ELI5_MODE', None),
('LAST30DAYS_YOUTUBE_SSH_HOST', None),
+ # Proxy for yt-dlp; YT_PROXY is the short alias. Only routes yt-dlp
+ # traffic — does not affect other HTTP calls the skill makes.
+ ('YOUTUBE_PROXY', None),
+ ('YT_PROXY', None),
('LAST30DAYS_REPORT_CACHE_TTL_SECONDS', None),
('LAST30DAYS_VERIFY_FRESHNESS', None),
('LAST30DAYS_TRANSCRIPT_TIMEOUT', None),
diff --git a/skills/last30days/scripts/lib/youtube_yt.py b/skills/last30days/scripts/lib/youtube_yt.py
index 9c12ed94..50582c04 100644
--- a/skills/last30days/scripts/lib/youtube_yt.py
+++ b/skills/last30days/scripts/lib/youtube_yt.py
@@ -401,6 +401,19 @@ def _inject_youtube_player_client(cmd: List[str]) -> List[str]:
return out
+def _ytdlp_proxy() -> Optional[str]:
+ """Return the proxy URL for yt-dlp, or None when unset.
+
+ Set ``YOUTUBE_PROXY`` (or ``YT_PROXY``) to any proxy URL that yt-dlp
+ accepts: ``socks5://127.0.0.1:1080``, ``http://proxy:3128``, etc.
+ ``YOUTUBE_PROXY`` takes precedence over ``YT_PROXY``. Only routes
+ yt-dlp traffic through the proxy — other HTTP requests the skill makes
+ are unaffected (use ``HTTP_PROXY`` / ``HTTPS_PROXY`` for those).
+ """
+ proxy = os.environ.get("YOUTUBE_PROXY", "").strip() or os.environ.get("YT_PROXY", "").strip()
+ return proxy or None
+
+
def _wrap_ytdlp_cmd(cmd: List[str]) -> List[str]:
"""Wrap a yt-dlp command list with `ssh <host>` when SSH routing is set.
@@ -410,6 +423,9 @@ def _wrap_ytdlp_cmd(cmd: List[str]) -> List[str]:
LAST30DAYS_YOUTUBE_SSH_HOST were ever set to a value starting with `-`.
"""
cmd = _inject_youtube_player_client(cmd)
+ proxy = _ytdlp_proxy()
+ if proxy:
+ cmd = list(cmd) + ["--proxy", proxy]
host = _ytdlp_ssh_host()
if not host:
return cmd
@@ -807,11 +823,14 @@ def _fetch_transcript_ytdlp_via_ssh(video_id: str, ssh_host: str) -> Optional[st
if client
else ""
)
+ proxy = _ytdlp_proxy()
+ proxy_flag = f"--proxy {shlex.quote(proxy)} " if proxy else ""
remote_script = (
"set -e; "
"TMPD=$(mktemp -d); "
"yt-dlp --ignore-config --no-cookies-from-browser "
f"{extractor}"
+ f"{proxy_flag}"
f"--write-auto-subs --sub-lang {sub_langs} --sub-format vtt "
"--skip-download --no-warnings "
f'-o "$TMPD/%(id)s" {quoted_url} >/dev/null 2>&1 || true; '
@@ -933,6 +952,9 @@ def _fetch_transcript_ytdlp(
f"https://www.youtube.com/watch?v={video_id}",
]
cmd = _inject_youtube_player_client(cmd)
+ proxy = _ytdlp_proxy()
+ if proxy:
+ cmd = list(cmd) + ["--proxy", proxy]
timeout = _transcript_fast_timeout() if fast_fail else _TRANSCRIPT_TIMEOUT
attempts = 1 if fast_fail else _TRANSCRIPT_MAX_RETRIES + 1
diff --git a/tests/test_youtube_yt.py b/tests/test_youtube_yt.py
index 4d424007..f348ba3b 100644
--- a/tests/test_youtube_yt.py
+++ b/tests/test_youtube_yt.py
@@ -1853,6 +1853,54 @@ class TestYtdlpPlayerClient(unittest.TestCase):
self.assertEqual(youtube_yt._inject_youtube_player_client(cmd), cmd)
+class TestYoutubeProxy(unittest.TestCase):
+ """_ytdlp_proxy reads YOUTUBE_PROXY / YT_PROXY and _wrap_ytdlp_cmd injects it."""
+
+ def test_no_env_returns_none(self):
+ with mock.patch.dict(os.environ, {}, clear=False):
+ os.environ.pop("YOUTUBE_PROXY", None)
+ os.environ.pop("YT_PROXY", None)
+ self.assertIsNone(youtube_yt._ytdlp_proxy())
+
+ def test_youtube_proxy_env(self):
+ with mock.patch.dict(os.environ, {"YOUTUBE_PROXY": "socks5://127.0.0.1:1080"}, clear=False):
+ os.environ.pop("YT_PROXY", None)
+ self.assertEqual(youtube_yt._ytdlp_proxy(), "socks5://127.0.0.1:1080")
+
+ def test_yt_proxy_alias(self):
+ with mock.patch.dict(os.environ, {"YT_PROXY": "http://proxy:3128"}, clear=False):
+ os.environ.pop("YOUTUBE_PROXY", None)
+ self.assertEqual(youtube_yt._ytdlp_proxy(), "http://proxy:3128")
+
+ def test_youtube_proxy_takes_precedence_over_yt_proxy(self):
+ with mock.patch.dict(os.environ, {"YOUTUBE_PROXY": "socks5://a:1", "YT_PROXY": "http://b:2"}, clear=False):
+ self.assertEqual(youtube_yt._ytdlp_proxy(), "socks5://a:1")
+
+ def test_empty_env_returns_none(self):
+ with mock.patch.dict(os.environ, {"YOUTUBE_PROXY": " "}, clear=False):
+ os.environ.pop("YT_PROXY", None)
+ self.assertIsNone(youtube_yt._ytdlp_proxy())
+
+ def test_wrap_cmd_injects_proxy(self):
+ env_patch = {"YOUTUBE_PROXY": "socks5://127.0.0.1:1080"}
+ with mock.patch.dict(os.environ, env_patch, clear=False):
+ os.environ.pop("YT_PROXY", None)
+ os.environ.pop("LAST30DAYS_YOUTUBE_SSH_HOST", None)
+ cmd = ["yt-dlp", "--ignore-config", "ytsearch5:test", "--dump-json"]
+ result = youtube_yt._wrap_ytdlp_cmd(cmd)
+ self.assertIn("--proxy", result)
+ self.assertIn("socks5://127.0.0.1:1080", result)
+
+ def test_wrap_cmd_no_proxy_when_unset(self):
+ with mock.patch.dict(os.environ, {}, clear=False):
+ os.environ.pop("YOUTUBE_PROXY", None)
+ os.environ.pop("YT_PROXY", None)
+ os.environ.pop("LAST30DAYS_YOUTUBE_SSH_HOST", None)
+ cmd = ["yt-dlp", "--ignore-config", "ytsearch5:test", "--dump-json"]
+ result = youtube_yt._wrap_ytdlp_cmd(cmd)
+ self.assertNotIn("--proxy", result)
+
+
class TestYouTubeDateWindowByFreshnessMode(unittest.TestCase):
"""Out-of-window soft fallback is scoped to evergreen_ok (recent topics stay honest)."""