From 93f7b5f71436d8dcdef474f63b5ddaef67428f13 Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 21 May 2025 10:11:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B=E6=97=B6?= =?UTF-8?q?=E9=95=BF=E8=AE=A1=E7=AE=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wechat_ipad/client/message.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wechat_ipad/client/message.py b/wechat_ipad/client/message.py index 3f8984a..66e8475 100644 --- a/wechat_ipad/client/message.py +++ b/wechat_ipad/client/message.py @@ -237,7 +237,15 @@ class MessageMixin(WechatAPIClientBase): media_info = MediaInfo.parse(video_path) else: raise ValueError("video should be str, bytes, or path") - duration = media_info.tracks[0].duration + # 获取视频时长 + duration = None + for track in media_info.tracks: + if track.track_type == "Video" and track.duration is not None: + duration = track.duration / 1000 # 将毫秒转换为秒 + break + if duration is None: + duration = 1 + self.logging.error(f"无法从视频文件获取时长: {video}") # get image base64 if isinstance(image, str): @@ -256,7 +264,7 @@ class MessageMixin(WechatAPIClientBase): self.logging.info("开始发送视频: 对方wxid:{} 视频base64略 图片base64略 预计耗时:{}秒", wxid, predict_time) async with aiohttp.ClientSession() as session: - json_param = {"Wxid": self.wxid, "ToWxid": wxid, "Base64": "data:video/mp4;base64,"+vid_base64, + json_param = {"Wxid": self.wxid, "ToWxid": wxid, "Base64": "data:video/mp4;base64," + vid_base64, "ImageBase64": "data:image/jpeg;base64," + image_base64, "PlayLength": duration} # self.logging.debug(f"json_param::{json_param}")