feature:抖音分享链接转视频
This commit is contained in:
@@ -9,6 +9,7 @@ from typing import Dict, Any
|
|||||||
from wcferry import WxMsg, Wcf
|
from wcferry import WxMsg, Wcf
|
||||||
|
|
||||||
from robot_cmd.robot_command import GroupBotManager, Feature, PermissionStatus
|
from robot_cmd.robot_command import GroupBotManager, Feature, PermissionStatus
|
||||||
|
import lz4.block as lb
|
||||||
|
|
||||||
|
|
||||||
class DouyinParserError(Exception):
|
class DouyinParserError(Exception):
|
||||||
@@ -33,7 +34,7 @@ class DouyinParser:
|
|||||||
|
|
||||||
self.enable = config.get("enable", True)
|
self.enable = config.get("enable", True)
|
||||||
self.http_proxy = config.get("http_proxy", None)
|
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]:
|
def _clean_response_data(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
if not data:
|
if not data:
|
||||||
@@ -126,33 +127,74 @@ class DouyinParser:
|
|||||||
author = video_info.get('name', '未知作者')
|
author = video_info.get('name', '未知作者')
|
||||||
if not video_url:
|
if not video_url:
|
||||||
raise DouyinParserError("无法获取视频地址")
|
raise DouyinParserError("无法获取视频地址")
|
||||||
file_abspath = self.download_video(video_url, "douyin_parser/down_load_dir")
|
self.send_xml_video(message, title, author, video_url)
|
||||||
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))
|
|
||||||
except Exception as e:
|
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):
|
def send_xml_video(self, message: WxMsg, title, author, video_url):
|
||||||
# 确保 save_dir 是一个目录
|
|
||||||
if os.path.isfile(save_dir):
|
|
||||||
print(f"错误: {save_dir} 是一个文件,不能作为目录使用。")
|
|
||||||
return None
|
|
||||||
|
|
||||||
os.makedirs(save_dir, exist_ok=True)
|
xml_message = f"""
|
||||||
save_path = os.path.join(save_dir, "video.mp4")
|
<?xml version="1.0"?>
|
||||||
if video_url:
|
<msg>
|
||||||
video_response = requests.get(video_url, stream=True)
|
<appmsg appid="" sdkver="1">
|
||||||
if video_response.status_code == 200:
|
<title>{title} @{author}</title>
|
||||||
with open(save_path, "wb") as file:
|
<des>点击观看无水印视频</des>
|
||||||
for chunk in video_response.iter_content(chunk_size=1024):
|
<action>view</action>
|
||||||
file.write(chunk)
|
<type>5</type>
|
||||||
abs_path = os.path.abspath(save_path)
|
<showtype>0</showtype>
|
||||||
print(f"视频已下载至: {abs_path}")
|
<content />
|
||||||
return abs_path
|
<url>{video_url}</url>
|
||||||
else:
|
<dataurl />
|
||||||
print("无法下载视频,HTTP 状态码:", video_response.status_code)
|
<lowurl />
|
||||||
else:
|
<lowdataurl />
|
||||||
print("API 响应中没有找到视频 URL")
|
<recorditem />
|
||||||
return None
|
<thumburl></thumburl>
|
||||||
|
<messageaction />
|
||||||
|
<laninfo />
|
||||||
|
<extinfo />
|
||||||
|
<sourceusername />
|
||||||
|
<sourcedisplayname />
|
||||||
|
<commenturl />
|
||||||
|
<appattach>
|
||||||
|
<totallen>0</totallen>
|
||||||
|
<attachid />
|
||||||
|
<emoticonmd5 />
|
||||||
|
<fileext />
|
||||||
|
<aeskey />
|
||||||
|
</appattach>
|
||||||
|
<webviewshared>
|
||||||
|
<publisherId />
|
||||||
|
<publisherReqId>0</publisherReqId>
|
||||||
|
</webviewshared>
|
||||||
|
<weappinfo>
|
||||||
|
<pagepath />
|
||||||
|
<username />
|
||||||
|
<appid />
|
||||||
|
<appservicetype>0</appservicetype>
|
||||||
|
</weappinfo>
|
||||||
|
<websearch />
|
||||||
|
</appmsg>
|
||||||
|
<fromusername>Jyunere</fromusername>
|
||||||
|
<scene>0</scene>
|
||||||
|
<appinfo>
|
||||||
|
<version>1</version>
|
||||||
|
<appname></appname>
|
||||||
|
</appinfo>
|
||||||
|
<commenturl></commenturl>
|
||||||
|
</msg>
|
||||||
|
|
||||||
|
"""
|
||||||
|
# 修改消息数据库里面的消息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}")
|
||||||
|
|||||||
Reference in New Issue
Block a user