Rate limit only background batch fetches, not user requests
fetch_video_metadata and fetch_channel_metadata now take polite=True for background tasks (enforces 5s+ gap via global lock) while user-facing calls (watch page, follow channel, download) use polite=False and run immediately. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -92,7 +92,7 @@ def _index_channel_task(channel_id: int, user_id: int, max_videos: int = 30):
|
||||
if not channel:
|
||||
return
|
||||
|
||||
result = ytdlp.fetch_channel_metadata(channel.youtube_channel_id, max_videos=max_videos)
|
||||
result = ytdlp.fetch_channel_metadata(channel.youtube_channel_id, max_videos=max_videos, polite=True)
|
||||
if not result:
|
||||
return
|
||||
|
||||
@@ -206,7 +206,7 @@ def _enrich_missing_task(limit: int = 20):
|
||||
).mappings().all()
|
||||
for row in rows:
|
||||
try:
|
||||
meta = ytdlp.fetch_video_metadata(row["youtube_video_id"])
|
||||
meta = ytdlp.fetch_video_metadata(row["youtube_video_id"], polite=True)
|
||||
if meta:
|
||||
vid = db.query(Video).filter_by(id=row["id"]).first()
|
||||
if vid:
|
||||
@@ -820,7 +820,7 @@ def _fetch_popular_task(channel_id: int, youtube_channel_id: str, channel_name:
|
||||
try:
|
||||
for yt_id in video_ids:
|
||||
try:
|
||||
meta = ytdlp.fetch_video_metadata(yt_id)
|
||||
meta = ytdlp.fetch_video_metadata(yt_id, polite=True)
|
||||
if meta:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
@@ -866,7 +866,7 @@ def _search_channel_task(channel_id: int, youtube_channel_id: str, q: str, user_
|
||||
db = SessionLocal()
|
||||
try:
|
||||
url = f"https://www.youtube.com/channel/{youtube_channel_id}/search?query={quote(q)}"
|
||||
result = ytdlp.fetch_channel_metadata(youtube_channel_id, max_videos=100)
|
||||
result = ytdlp.fetch_channel_metadata(youtube_channel_id, max_videos=100, polite=True)
|
||||
if not result:
|
||||
return
|
||||
# Filter results by query match (yt-dlp fetches all; we filter titles locally)
|
||||
@@ -1050,7 +1050,7 @@ def _index_channel_explore_task(channel_id: int, user_id: int, start_video: int,
|
||||
channel = db.query(Channel).filter_by(id=channel_id).first()
|
||||
if not channel:
|
||||
return
|
||||
result = ytdlp.fetch_channel_metadata(channel.youtube_channel_id, max_videos=count, start_video=start_video)
|
||||
result = ytdlp.fetch_channel_metadata(channel.youtube_channel_id, max_videos=count, start_video=start_video, polite=True)
|
||||
if not result:
|
||||
return
|
||||
for vdata in result.get("videos", []):
|
||||
|
||||
Reference in New Issue
Block a user