From e44d8f942071762dd7794e0127ca24258690628c Mon Sep 17 00:00:00 2001 From: liuwei Date: Tue, 11 Mar 2025 11:00:29 +0800 Subject: [PATCH] =?UTF-8?q?feature=EF=BC=9A=E6=8A=96=E9=9F=B3=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E9=93=BE=E6=8E=A5=E8=BD=AC=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin_parser/main.py | 98 ++++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 28 deletions(-) diff --git a/douyin_parser/main.py b/douyin_parser/main.py index 5bc0c7e..62a950a 100644 --- a/douyin_parser/main.py +++ b/douyin_parser/main.py @@ -9,6 +9,7 @@ from typing import Dict, Any from wcferry import WxMsg, Wcf from robot_cmd.robot_command import GroupBotManager, Feature, PermissionStatus +import lz4.block as lb class DouyinParserError(Exception): @@ -33,7 +34,7 @@ class DouyinParser: self.enable = config.get("enable", True) self.http_proxy = config.get("http_proxy", None) - self.LOG.debug("[抖音] 插件初始化完成,代理设置: %s", self.http_proxy) + self.LOG.info("[抖音] 插件初始化完成,代理设置: %s", self.http_proxy) def _clean_response_data(self, data: Dict[str, Any]) -> Dict[str, Any]: if not data: @@ -126,33 +127,74 @@ class DouyinParser: author = video_info.get('name', '未知作者') if not video_url: raise DouyinParserError("无法获取视频地址") - file_abspath = self.download_video(video_url, "douyin_parser/down_load_dir") - self.wcf.send_file(file_abspath, (message.roomid if message.from_group() else message.sender)) - self.LOG.info("已发送解析结果: 标题[%s] 作者[%s]", title, author) - except DouyinParserError as e: - self.LOG.error("抖音解析失败: %s", str(e)) + self.send_xml_video(message, title, author, video_url) except Exception as e: - self.LOG.error("抖音解析发生未知错误: %s", str(e)) + self.LOG.error("[抖音] 解析过程发生未知错误: %s\n%s", str(e), traceback.format_exc()) + raise DouyinParserError(f"未知错误: {str(e)}") + return - def download_video(self, video_url, save_dir): - # 确保 save_dir 是一个目录 - if os.path.isfile(save_dir): - print(f"错误: {save_dir} 是一个文件,不能作为目录使用。") - return None + def send_xml_video(self, message: WxMsg, title, author, video_url): - os.makedirs(save_dir, exist_ok=True) - save_path = os.path.join(save_dir, "video.mp4") - if video_url: - video_response = requests.get(video_url, stream=True) - if video_response.status_code == 200: - with open(save_path, "wb") as file: - for chunk in video_response.iter_content(chunk_size=1024): - file.write(chunk) - abs_path = os.path.abspath(save_path) - print(f"视频已下载至: {abs_path}") - return abs_path - else: - print("无法下载视频,HTTP 状态码:", video_response.status_code) - else: - print("API 响应中没有找到视频 URL") - return None + xml_message = f""" + + + + {title} @{author} + 点击观看无水印视频 + view + 5 + 0 + + {video_url} + + + + + + + + + + + + + 0 + + + + + + + + 0 + + + + + + 0 + + + + Jyunere + 0 + + 1 + + + + + + """ + # 修改消息数据库里面的消息content 内容 + text_bytes = xml_message.encode('utf-8') + compressed_data = lb.compress(text_bytes, store_size=False).hex() + + data = self.wcf.query_sql('MSG0.db', "SELECT * FROM MSG where type = 49 limit 1") + self.wcf.query_sql('MSG0.db', + f"""UPDATE MSG SET CompressContent = x'{compressed_data}', BytesExtra=x'', type=49, SubType=3, + IsSender=0, TalkerId=2 WHERE MsgSvrID={data[0]['MsgSvrID']}""" + ) + + result = self.wcf.forward_msg(data[0]["MsgSvrID"], message.roomid) + print(f"视频链接:{result}")