diff --git a/plugins/douyin_parser/main.py b/plugins/douyin_parser/main.py index 69890d4..f8436a6 100644 --- a/plugins/douyin_parser/main.py +++ b/plugins/douyin_parser/main.py @@ -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 "{}")