diff --git a/wechat_ipad/client/message.py b/wechat_ipad/client/message.py index 7fcacf2..517c19a 100644 --- a/wechat_ipad/client/message.py +++ b/wechat_ipad/client/message.py @@ -216,6 +216,9 @@ class MessageMixin(WechatAPIClientBase): ValueError: 视频或图片参数都为空或都不为空时 根据error_handler处理错误 """ + has_image = False + if not image: + image = Path(os.path.join(Path(__file__).resolve().parent, "fallback.png")) # get video base64 and duration if isinstance(video, str): @@ -236,9 +239,11 @@ class MessageMixin(WechatAPIClientBase): file_len = len(video_bytes) vid_base64 = base64.b64encode(video_bytes).decode() media_info = MediaInfo.parse(video_path) - first_frame = _get_first_frame(video_path, f"dify_frame_{int(time.time())}.jpg") - if first_frame: - image = first_frame + # 如果没有传入首帧,则自己提取一次 + if not has_image: + first_frame = _get_first_frame(video_path, f"dify_frame_{int(time.time())}.jpg") + if first_frame: + image = first_frame else: raise ValueError("video should be str, bytes, or path") # 获取视频时长 @@ -250,8 +255,6 @@ class MessageMixin(WechatAPIClientBase): if duration is None: duration = 1 self.logging.error(f"无法从视频文件获取时长: {video}") - if not image: - image = Path(os.path.join(Path(__file__).resolve().parent, "fallback.png")) # get image base64 if isinstance(image, str): image_base64 = image