fix(douyin): staging环境默认开启debug详情+关键路径加详细日志定位502根因
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 0s
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
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 / Check push changed paths (push) Successful in 3s
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 41s
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 17s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 44s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 3m4s
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Successful in 3m49s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 1m55s
CI/CD Pipeline / Integration Tests (push) Successful in 4m56s
CI/CD Pipeline / Validate - Style (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
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 - Security (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled

This commit is contained in:
2026-09-17 14:52:43 +08:00
parent 46bce0dee8
commit fac88318bd
+20 -4
View File
@@ -101,7 +101,11 @@ else:
DOUYIN_COOKIES_FILE_BAKED,
)
_DOUYIN_DEBUG_ERRORS = os.environ.get("DOUYIN_DEBUG_ERRORS", "").lower() in ("1", "true", "yes")
_DOUYIN_DEBUG_ERRORS = os.environ.get("DOUYIN_DEBUG_ERRORS", "").lower() in (
"1",
"true",
"yes",
) or os.environ.get("APP_ENV", "").lower() in ("staging", "dev", "development", "test")
_URL_EXTRACT_RE = re.compile(r"https?://\S+", re.IGNORECASE)
_DOUYIN_HOST_RE = re.compile(
@@ -307,7 +311,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",
@@ -442,6 +446,7 @@ def _ytdlp_extract_video_url(page_url, cookiefile=None, max_retries=10):
import time as _time
ttwid = _fetch_ttwid()
logger.info("ytdlp 直链提取开始: page_url=%s ttwid_ok=%s max_retries=%d", page_url, bool(ttwid), max_retries)
with tempfile.TemporaryDirectory(prefix="dy_ytdlp_cookies_") as tmpdir:
for attempt in range(max_retries):
if attempt % 3 == 0:
@@ -450,8 +455,9 @@ def _ytdlp_extract_video_url(page_url, cookiefile=None, max_retries=10):
info, err = _ytdlp_try_extract(page_url, gen_cookie)
if info:
vurl = info.get("url")
logger.info("yt-dlp 合成 cookie 第%d次尝试成功", attempt + 1)
logger.info("yt-dlp 合成 cookie 第%d次尝试成功: vurl_domain=%s", attempt + 1, vurl.split("/")[2] if vurl and "/" in vurl else "?")
return (vurl, float(info.get("duration") or 0.0)) if vurl else (None, 0.0)
logger.info("yt-dlp 合成 cookie 第%d次尝试失败: %s", attempt + 1, str(err)[:150])
_time.sleep(0.4)
logger.info("yt-dlp 合成 cookie 全部 %d 次重试均失败", max_retries)
@@ -717,7 +723,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:
@@ -731,11 +737,21 @@ def _ytdlp_download_and_local_asr(page_url, temp_dir, cookiefile=None):
vpath, duration = _download(cfile)
if vpath and os.path.isfile(vpath) and os.path.getsize(vpath) > 0:
break
logger.warning(
"ytdlp 下载返回路径无效或空文件: vpath=%s size=%s",
vpath,
os.path.getsize(vpath) if vpath and os.path.isfile(vpath) else "N/A",
)
except Exception as exc: # noqa: BLE001
last_err = exc
logger.warning("ytdlp 下载重试失败: %s", str(exc)[:200])
continue
else:
msg = str(last_err) if last_err else "unknown"
logger.warning(
"ytdlp 下载全部 %d 次 cookie 尝试均失败: ttwid_ok=%s last_err=%s",
len(cookie_files_to_try), bool(ttwid), msg[:300],
)
if _is_cookies_related_error(msg) or "Fresh cookies" in msg:
_detail = "抖音链接解析暂时不可用,请稍后重试或手动输入文案"
if _DOUYIN_DEBUG_ERRORS: