diff --git a/apps/api/app/api/routes/scripts_ai.py b/apps/api/app/api/routes/scripts_ai.py index f8217e740..c37575728 100644 --- a/apps/api/app/api/routes/scripts_ai.py +++ b/apps/api/app/api/routes/scripts_ai.py @@ -356,7 +356,7 @@ def _fetch_ttwid(): # 方式一:直接调 ttwid 注册接口 try: with httpx.Client(timeout=8, follow_redirects=True, verify=False) as http: - http.post( + r = http.post( "https://ttwid.bytedance.com/ttwid/union/register/", json={ "region": "cn", @@ -769,7 +769,7 @@ def _ytdlp_download_and_local_asr(page_url, temp_dir, cookiefile=None): cookie_files_to_try.append(cookiefile) # 2. 合成 cookie 重试(复用 _ytdlp_extract 的 cookie 生成逻辑,8次重试) - import time as _time + import secrets, time as _time ttwid = _fetch_ttwid() for i in range(8): if i % 3 == 0: @@ -945,10 +945,9 @@ def _html_scrape_direct_url(page_url, timeout=15): @router.get("/douyin/__debug_diag") def douyin_diag(): """[Staging only] 容器内网络/yt-dlp诊断""" - import tempfile as _tf - import time as _t - import httpx as _httpx + import time as _t + import tempfile as _tf import yt_dlp as _ytdlp results = {} @@ -1126,11 +1125,23 @@ def extract_from_douyin( direct_url, feed_desc = _feed_fetch(page_url, timeout=15, max_retries=3) if direct_url: logger.info("抖音 App Feed API 直连成功: url=%s play_len=%d", page_url, len(direct_url)) + elif feed_desc: + logger.info("抖音 App Feed API 返回图文视频,仅用文案: desc_len=%d", len(feed_desc)) except Exception as exc: # noqa: BLE001 logger.warning("抖音 App Feed API 异常: %s", exc) text = "" duration = 0.0 + # 图文视频(direct_url 为 None 但 feed_desc 有文案)直接返回文案,跳过 ASR + if not direct_url and feed_desc: + text = feed_desc.strip() + logger.info("图文视频直接返回文案: url=%s text_len=%d", page_url, len(text)) + return ExtractFromDouyinResponse( + text=text, + duration_seconds=0.0, + source_url=page_url, + ) + cookiefile = _resolve_cookies_file() mk_client = get_mediakit_client()