fix(douyin): ASR返回空时(无旁白视频)使用Feed desc兜底,避免503
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 1s
CI/CD Pipeline / Check push changed paths (push) Successful in 1s
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / Build Staging Web Image (push) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 36s
CI/CD Pipeline / Build Staging API Image (push) Successful in 40s
CI/CD Pipeline / Retag skipped Staging API Image (push) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (push) Successful in 1m37s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 2m23s
CI/CD Pipeline / Integration Tests (push) Successful in 3m9s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 51s
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / Canary Release to Production (push) Has been cancelled
CI/CD Pipeline / CI Gate (push) Has been cancelled
CI/CD Pipeline / Validate - Style (push) Has been cancelled
CI/CD Pipeline / Validate - Security (push) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled

This commit is contained in:
2026-09-17 17:54:33 +08:00
parent 1c9d5f81bb
commit c2d8ebab4b
+23 -10
View File
@@ -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 = {}
@@ -1244,17 +1243,31 @@ def extract_from_douyin(
if text:
break
# ASR 可能返回空(视频无旁白/只有BGM/环境音),此时用 feed_desc 作为文案兜底
if feed_desc and not text:
text = feed_desc.strip()
logger.info(
"抖音 ASR 未识别到语音(第%d轮),使用 Feed API desc 作为文案: desc_len=%d",
round_idx + 1, len(text),
)
break
# 本轮全链路失败,等一下重试(直链未拿到可能是瞬时限流)
if round_idx < max_rounds - 1:
logger.info("第%d轮全链路失败,等待后重试", round_idx + 1)
time.sleep(1.5)
if not text:
logger.warning("抖音文案提取全部失败: url=%s", page_url)
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="抖音链接解析暂时不可用,请稍后重试或手动输入文案",
)
# 终极兜底:所有 ASR 路径均失败/返回空时,若 Feed API 拿到了 desc 就直接用
if feed_desc:
text = feed_desc.strip()
logger.info("抖音所有 ASR 路径均失败,最终使用 Feed desc 作为文案: desc_len=%d", len(text))
else:
logger.warning("抖音文案提取全部失败: url=%s", page_url)
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="抖音链接解析暂时不可用,请稍后重试或手动输入文案",
)
return ExtractFromDouyinResponse(
text=text,