SurfSense/surfsense_backend/app/capabilities/tiktok/trending/executor.py
CREDO23 67b5472b9f feat(tiktok): add tiktok.trending verb for the Explore feed
The Explore feed (/api/explore/item_list) is a global trending-video feed
served to anonymous sessions, and it returns the same itemStruct shape as the
other listings — so the verb reuses parse_video, the listing flow, the
TikTokVideoItem output, and the per-video billing meter wholesale. Adds a
browser-capture marker + fetch_trending, a synthetic-target orchestrator entry,
and the tiktok.trending capability, surfaced on the chat subagent.
2026-07-09 18:52:56 +02:00

32 lines
1.1 KiB
Python

"""``tiktok.trending`` executor: Explore feed -> scraper -> TikTok video items."""
from __future__ import annotations
from collections.abc import Awaitable, Callable
from app.capabilities.core import Executor
from app.capabilities.core.progress import emit_progress
from app.capabilities.tiktok.trending.schemas import TrendingInput, TrendingOutput
from app.proprietary.platforms.tiktok import scrape_tiktok_trending
TrendingFn = Callable[..., Awaitable[list[dict]]]
def build_trending_executor(trending_fn: TrendingFn | None = None) -> Executor:
"""Bind the executor to a trending fn (defaults to the proprietary actor)."""
trending_fn = trending_fn or scrape_tiktok_trending
async def execute(payload: TrendingInput) -> TrendingOutput:
emit_progress(
"starting",
"Fetching TikTok trending videos",
total=payload.max_items,
unit="item",
)
items = await trending_fn(count=payload.max_items)
emit_progress(
"done", f"Fetched {len(items)} video(s)", current=len(items), unit="item"
)
return TrendingOutput(items=items)
return execute