Route all discovery fetches through global rate limiter

- search_youtube, fetch_trending, fetch_featured_channels now use _meta_run
- Replaced ThreadPoolExecutor(4) parallel searches with sequential loop
- Replaced ThreadPoolExecutor(3) parallel featured-channel fetches with sequential
- _fetch_and_index_channel passes polite=True to fetch_channel/video_metadata

Discovery was firing 4+ simultaneous yt-dlp processes, each with cookies,
which is what invalidated the session.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 01:05:56 +02:00
parent 4a7f1f06ac
commit 19dae63385
2 changed files with 27 additions and 38 deletions

View File

@@ -152,7 +152,7 @@ def _normalize_channel(info: dict) -> dict:
def search_youtube(query: str, max_results: int = 40) -> list[dict]:
"""Search YouTube via yt-dlp. Uses --flat-playlist for fast results."""
stdout, _, code = _run([
stdout, _, code = _meta_run([
"yt-dlp",
f"ytsearch{max_results}:{query}",
"--dump-json",
@@ -199,7 +199,7 @@ def fetch_trending(region: str = "US", max_results: int = 50) -> list[dict]:
region = region.upper()
# CAI%3D = sort by upload date; gl= sets the region
url = f"https://www.youtube.com/results?search_query=trending&sp=CAI%253D&gl={region}"
stdout, _, code = _run([
stdout, _, code = _meta_run([
"yt-dlp",
url,
"--dump-json",
@@ -474,7 +474,7 @@ def fetch_featured_channels(channel_id: str) -> list[str]:
url = f"https://www.youtube.com/{channel_id}/channels"
else:
url = f"https://www.youtube.com/channel/{channel_id}/channels"
stdout, _, code = _run([
stdout, _, code = _meta_run([
"yt-dlp", url,
"--dump-json",
"--flat-playlist",