| 123456789101112131415161718192021222324252627282930313233343536 |
- """公共工具:异常、停顿、步骤重试。"""
- from __future__ import annotations
- import random
- import time
- class SkipVideoError(Exception):
- """当前视频不满足采集条件(如一级评论不足),应跳过并切下一条。"""
- AI_SUMMARY_PROMPT = "用20~30个字总结该视频内容"
- def human_pause(min_s: float = 1.5, max_s: float = 3.5) -> None:
- seconds = random.uniform(min_s, max_s)
- print(f"等待 {seconds:.1f}s ...")
- time.sleep(seconds)
- def run_step(name: str, action) -> bool:
- for attempt in (1, 2):
- try:
- print(f"[{name}] 开始(第 {attempt} 次)")
- action()
- print(f"[{name}] 完成")
- return True
- except Exception as exc:
- print(f"[{name}] 失败: {exc}")
- if attempt == 1:
- print(f"[{name}] 准备重试一次...")
- human_pause(2.0, 4.0)
- else:
- print(f"[{name}] 重试仍失败,跳过该步骤,浏览器保持打开。")
- return False
|