refactor(youtube): drop duplicate POST /youtube/scrape+comments routes (use capability doors)

This commit is contained in:
CREDO23 2026-07-03 11:38:56 +02:00
parent c66b2f0e0e
commit 62cb0efb44

View file

@ -9,12 +9,6 @@ from fastapi import APIRouter, Depends, HTTPException, Query
from scrapling.fetchers import AsyncFetcher
from app.auth.context import AuthContext
from app.proprietary.platforms.youtube import (
YouTubeCommentsInput,
YouTubeScrapeInput,
scrape_comments,
scrape_youtube,
)
from app.users import require_session_context
from app.utils.proxy import get_proxy_url
@ -32,45 +26,6 @@ _INNERTUBE_CLIENT = {
}
@router.post("/youtube/scrape")
async def scrape_youtube_route(
payload: YouTubeScrapeInput,
_auth: AuthContext = Depends(require_session_context),
) -> list[dict]:
"""Scrape public YouTube data (search / video / channel / playlist / shorts).
Apify YouTube Scraper-compatible input/output. The scrape runs inline and is
bounded only by the request's own ``maxResults`` / ``maxResultsShorts`` /
``maxResultStreams`` no separate per-request ceiling.
"""
try:
return await scrape_youtube(payload)
except Exception as e:
logger.error("YouTube scrape failed: %s", e)
raise HTTPException(
status_code=502, detail=f"YouTube scrape failed: {e!s}"
) from e
@router.post("/youtube/comments")
async def scrape_comments_route(
payload: YouTubeCommentsInput,
_auth: AuthContext = Depends(require_session_context),
) -> list[dict]:
"""Scrape YouTube comments (+ replies) for the given video URLs.
Apify "YouTube Comments Scraper"-compatible. Runs inline and is bounded only
by the request's own ``maxComments`` — no separate per-request ceiling.
"""
try:
return await scrape_comments(payload)
except Exception as e:
logger.error("YouTube comments scrape failed: %s", e)
raise HTTPException(
status_code=502, detail=f"YouTube comments scrape failed: {e!s}"
) from e
@router.get("/youtube/playlist-videos")
async def get_playlist_videos(
url: str = Query(..., description="YouTube playlist URL"),