Complete rate-limiter coverage for all background yt-dlp calls
- fetch_playlist_videos now uses _meta_run (background playlist indexing) - fetch_channel_links now uses _meta_run (dead code, future-proofed) - _upsert_video_from_yt accepts polite= flag; background enrichment passes polite=True - Only intentional user-facing one-shot calls (download_subs_only, fetch_video_comments, polite=False metadata) bypass the lock Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -513,9 +513,9 @@ def _row_to_detail(row) -> VideoDetail:
|
||||
)
|
||||
|
||||
|
||||
def _upsert_video_from_yt(db: Session, youtube_video_id: str) -> bool:
|
||||
def _upsert_video_from_yt(db: Session, youtube_video_id: str, polite: bool = False) -> bool:
|
||||
"""Fetch fresh metadata from yt-dlp and upsert video + channel. Returns True if successful."""
|
||||
meta = ytdlp.fetch_video_metadata(youtube_video_id)
|
||||
meta = ytdlp.fetch_video_metadata(youtube_video_id, polite=polite)
|
||||
if not meta:
|
||||
return False
|
||||
|
||||
@@ -868,7 +868,7 @@ def get_video_by_yt_id(
|
||||
def _enrich(yt_id: str):
|
||||
bg_db = SessionLocal()
|
||||
try:
|
||||
_upsert_video_from_yt(bg_db, yt_id)
|
||||
_upsert_video_from_yt(bg_db, yt_id, polite=True)
|
||||
finally:
|
||||
bg_db.close()
|
||||
background_tasks.add_task(_enrich, youtube_video_id)
|
||||
|
||||
@@ -435,7 +435,7 @@ def fetch_playlist_videos(playlist_id: str, max_videos: int = 200) -> list[dict]
|
||||
]
|
||||
if max_videos > 0:
|
||||
args += ["--playlist-end", str(max_videos)]
|
||||
stdout, _, code = _run(args, timeout=120)
|
||||
stdout, _, code = _meta_run(args, timeout=120)
|
||||
|
||||
videos = []
|
||||
for line in stdout.splitlines():
|
||||
@@ -503,7 +503,7 @@ def fetch_channel_links(channel_id: str) -> list[str]:
|
||||
url = f"https://www.youtube.com/{channel_id}/about"
|
||||
else:
|
||||
url = f"https://www.youtube.com/channel/{channel_id}/about"
|
||||
stdout, _, code = _run([
|
||||
stdout, _, code = _meta_run([
|
||||
"yt-dlp",
|
||||
url,
|
||||
"--dump-json",
|
||||
|
||||
Reference in New Issue
Block a user