抖音解析链路调整为本地业务优先并优化yt-dlp降噪

变更项:

- 调整解析优先级为:内网本地业务解析 -> 外部接口 -> yt-dlp兜底

- 避免在本地业务已可用时先触发 yt-dlp 导致 Fresh cookies 警告

- 对 yt-dlp 的 Fresh cookies 报错降级为 info 日志,减少误报噪音

- 保持现有消息发送结构不变,仅优化解析流程与日志体验
This commit is contained in:
liuwei
2026-04-23 15:48:35 +08:00
parent e0fa6e31ec
commit 80829dbb21

View File

@@ -240,23 +240,23 @@ class DouyinParserPlugin(MessagePluginInterface):
def _parse_douyin(self, url: str) -> Dict[str, Any]:
try:
clean_url = self._clean_url(url)
# 第一优先级:本地提取无需依赖远端解析API
# 1) 优先走 yt_dlp Python 库;
# 2) 若库不可用,再尝试系统已安装的 yt-dlp 命令行。
# 这样当接口异常/限流时,仍可在本机直接提取无水印直链和元数据。
local_fallback = self._parse_from_local_extractor(clean_url)
if local_fallback and (local_fallback.get('url') or local_fallback.get('images')):
return self._clean_response_data(local_fallback)
# 第二优先级:你现有的内网解析服务,作为本地提取失败后的兜底。
# 第一优先级:本地业务解析服务(内网),该链路与你指定的项目实现思路最接近,稳定性最高。
primary = self._parse_from_internal_api(clean_url)
if primary and (primary.get('url') or primary.get('images')):
return self._clean_response_data(primary)
# 第优先级:你现有的外部付费接口,作为最终兜底。
# 第优先级:外部接口兜底。
secondary = self._parse_from_external_api(clean_url)
if secondary and (secondary.get('url') or secondary.get('images')):
return self._clean_response_data(secondary)
# 第三优先级本机兜底提取yt-dlp
# 说明:
# - 该方案受 Cookie 新鲜度影响较大;
# - 放在最后可避免在“本地业务解析已成功”时仍输出 Fresh cookies 警告。
local_fallback = self._parse_from_local_extractor(clean_url)
if local_fallback and (local_fallback.get('url') or local_fallback.get('images')):
return self._clean_response_data(local_fallback)
raise DouyinParserError("未获取到有效媒资数据")
except Exception as e:
self.LOG.error(f"[抖音] 解析过程发生未知错误: {str(e)}\n{traceback.format_exc()}")
@@ -617,7 +617,12 @@ class DouyinParserPlugin(MessagePluginInterface):
result = subprocess.run(cmd, capture_output=True, text=True, timeout=25)
if result.returncode != 0:
self.LOG.warning(f"[抖音] yt-dlp 命令行提取失败: code={result.returncode}, err={result.stderr[:200]}")
err_msg = (result.stderr or "").strip().replace("\n", " ")
if "Fresh cookies" in err_msg:
# 该错误在抖音场景出现频率较高,且当前链路已是“最后兜底”,降为 info 避免误导。
self.LOG.info("[抖音] yt-dlp 兜底提取失败Cookie 需要刷新Fresh cookies needed")
else:
self.LOG.warning(f"[抖音] yt-dlp 命令行提取失败: code={result.returncode}, err={err_msg[:200]}")
return None
try:
data = json.loads(result.stdout or "{}")