From ffc9308794b823cce52e8a03d5a88b16c06f5d59 Mon Sep 17 00:00:00 2001 From: H Vs Date: Thu, 13 Feb 2025 11:01:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=89=E5=BE=85=E5=9B=9E=E5=BA=94=E5=BC=80?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/utils.py | 7 ++++--- docker/Dockerfile.latest | 2 +- resources/messages_resource.py | 8 +++++--- wechat/biz.py | 3 ++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/common/utils.py b/common/utils.py index 5b49190..f099daf 100644 --- a/common/utils.py +++ b/common/utils.py @@ -14,7 +14,7 @@ from voice import audio_convert import cv2 import os import tempfile -from moviepy import VideoFileClip +from moviepy.editor import VideoFileClip from common import redis_helper @@ -362,6 +362,7 @@ def download_video_and_get_thumbnail(url, thumbnail_path): 异常: 可能抛出requests.exceptions.RequestException,cv2.error,IOError等异常。 """ + logger.info("处理视频开始") # 创建临时目录以下载视频 with tempfile.TemporaryDirectory() as tmp_dir: # 下载视频到临时文件 @@ -393,7 +394,7 @@ def download_video_and_get_thumbnail(url, thumbnail_path): clip = VideoFileClip(video_path) duration = clip.duration clip.close() - + logger.info("处理视频完成") # OSS 配置(建议将凭证存储在安全的地方) oss_access_key_id="LTAI5tRTG6pLhTpKACJYoPR5" oss_access_key_secret="E7dMzeeMxq4VQvLg7Tq7uKf3XWpYfN" @@ -404,7 +405,7 @@ def download_video_and_get_thumbnail(url, thumbnail_path): # 上传文件到 OSS file_path = thumbnail_path file_url = upload_oss(oss_access_key_id, oss_access_key_secret, oss_endpoint, oss_bucket_name, file_path, oss_prefix) - + logger.info("上传缩略图") # 删除临时文件 try: os.remove(thumbnail_path) diff --git a/docker/Dockerfile.latest b/docker/Dockerfile.latest index cea42d1..cd037f8 100644 --- a/docker/Dockerfile.latest +++ b/docker/Dockerfile.latest @@ -25,7 +25,7 @@ RUN apt-get update \ && cd ${BUILD_PREFIX} \ && cp config-template.json config.json \ && /usr/local/bin/python -m pip install --no-cache --upgrade pip \ - && pip install --no-cache -r requirements.txt -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple + && pip install --no-cache -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ WORKDIR ${BUILD_PREFIX} diff --git a/resources/messages_resource.py b/resources/messages_resource.py index 7e784ad..0dc2829 100644 --- a/resources/messages_resource.py +++ b/resources/messages_resource.py @@ -226,7 +226,7 @@ def handle_text(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): # 设置定时器,1秒后检查任务是否超时。这里需要使用 lambda 来传递参数 timeout_timer = threading.Timer( timeout_duration, - lambda:check_timeout(task_thread, token_id, app_id, callback_to_user) + lambda:check_timeout(task_thread, token_id, wxid,app_id, callback_to_user) ) timeout_timer.start() @@ -235,10 +235,12 @@ def handle_text(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): # 取消定时器 timeout_timer.cancel() -def check_timeout( task_thread:threading.Thread, token_id, app_id, callback_to_user): +def check_timeout( task_thread:threading.Thread, token_id,wxid, app_id, callback_to_user): if task_thread.is_alive(): print(f"任务运行时间超过{timeout_duration}秒,token_id={token_id}, app_id={app_id}, callback_to_user={callback_to_user}") - gewe_chat.wxchat.post_text(token_id,app_id,callback_to_user,"亲,我正在组织回复的信息,请稍等一会") + wx_config = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid) + if bool(wx_config.get("chatWaitingMsgEnabled",True)): + gewe_chat.wxchat.post_text(token_id,app_id,callback_to_user,"亲,我正在组织回复的信息,请稍等一会") def ai_chat_text(token_id,app_id,wxid,msg_data,msg_content): start_time = time.time() # 记录任务开始时间 diff --git a/wechat/biz.py b/wechat/biz.py index f03f976..39d6267 100644 --- a/wechat/biz.py +++ b/wechat/biz.py @@ -240,8 +240,9 @@ def send_video_message(wxchat:gewe_chat.GeWeChatCom, token_id, app_id, agent_wxi filename = os.path.basename(parsed_url.path) tmp_file_path = os.path.join(os.getcwd(),'tmp', filename) # 拼接完整路径 thumbnail_path=tmp_file_path.replace('.mp4','.jpg') - video_duration,video_thumb_url =utils.download_video_and_get_thumbnail(file_url,thumbnail_path) + video_thumb_url,video_duration =utils.download_video_and_get_thumbnail(file_url,thumbnail_path) + print(f'视频缩略图 {video_thumb_url} 时长 {video_duration}') if wxchat.forward_video_aeskey == '': ret,ret_msg,res = wxchat.post_video(token_id, app_id, t, file_url,video_thumb_url,video_duration) if ret==200: