diff --git a/scripts/jimeng_video_gen.py b/scripts/jimeng_video_gen.py index 0fd865e..d6820ca 100644 --- a/scripts/jimeng_video_gen.py +++ b/scripts/jimeng_video_gen.py @@ -89,9 +89,19 @@ def _submit_and_poll(req_key, body, output_path, max_wait=180, poll_interval=10) if resp_code == 10000 and resp_data.get('status') == 'done': video_url = resp_data.get('video_url') if video_url: - # 下载视频 + # 下载视频(带重试) print(f"[即梦视频] 生成完成,正在下载...") - video_data = requests.get(video_url).content + video_data = None + for attempt in range(3): + try: + video_data = requests.get(video_url, timeout=60, verify=False).content + break + except Exception as e: + print(f"[即梦视频] 下载重试 ({attempt+1}/3): {e}") + import time as _t; _t.sleep(3) + if video_data is None: + print(f"[即梦视频] 下载失败,视频URL: {video_url[:200]}") + return None _ensure_dir(output_path) with open(output_path, 'wb') as f: f.write(video_data) @@ -101,7 +111,7 @@ def _submit_and_poll(req_key, body, output_path, max_wait=180, poll_interval=10) print(f"[即梦视频] 任务完成但未找到视频URL: {json.dumps(result, ensure_ascii=False)[:300]}") return None - if resp_code != 10000 and resp_data.get('status') not in (None, 'running', 'pending'): + if resp_code != 10000 and (resp_data is None or resp_data.get('status') not in (None, 'running', 'pending')): print(f"[即梦视频] 任务失败: {json.dumps(result, ensure_ascii=False)[:300]}") return None