尝试支持图文信息

This commit is contained in:
liuwei
2026-01-27 17:37:19 +08:00
parent bae4b28203
commit 29d22ce83e

View File

@@ -155,6 +155,9 @@ class DouyinParserPlugin(MessagePluginInterface):
merged = self._merge_images_vertical(img_bytes_list, 1242) merged = self._merge_images_vertical(img_bytes_list, 1242)
if not merged: if not merged:
return False, "图片合并失败" return False, "图片合并失败"
title = media_info.get('title') or ""
if len(title) > 0:
await self.bot.send_text_message((roomid if roomid else sender), title)
await self.bot.send_image_message((roomid if roomid else sender), merged) await self.bot.send_image_message((roomid if roomid else sender), merged)
return True, "发送合并图片成功" return True, "发送合并图片成功"
else: else:
@@ -258,19 +261,21 @@ class DouyinParserPlugin(MessagePluginInterface):
images_field = data.get("images") or [] images_field = data.get("images") or []
images: List[str] = [] images: List[str] = []
for img in images_field: for img in images_field:
ulist = img.get("url_list") or img.get("download_url_list") or [] ulist = img.get("url_list") or img.get("download_url_list") or []
chosen = self._prefer_image_url(ulist) chosen = self._prefer_image_url(ulist)
if chosen: if chosen:
images.append(chosen) images.append(chosen)
desc = data.get("desc") or data.get("caption") or "" desc = data.get("desc") or data.get("caption") or ""
result = {"type": "image", "images": images, "title": desc, "author": nickname, "cover": images[0] if images else ""} result = {"type": "image", "images": images, "title": desc, "author": nickname,
"cover": images[0] if images else ""}
if images: if images:
return result return result
return None return None
video = data.get("video") or {} video = data.get("video") or {}
bit_rates = video.get("bit_rate") or [] bit_rates = video.get("bit_rate") or []
chosen_url = "" chosen_url = ""
mp4_sorted = sorted([br for br in bit_rates if br.get("format") == "mp4"], key=lambda x: x.get("bit_rate") or 0, reverse=True) mp4_sorted = sorted([br for br in bit_rates if br.get("format") == "mp4"],
key=lambda x: x.get("bit_rate") or 0, reverse=True)
for br in mp4_sorted: for br in mp4_sorted:
play_addr = br.get("play_addr") or {} play_addr = br.get("play_addr") or {}
urls = play_addr.get("url_list") or [] urls = play_addr.get("url_list") or []
@@ -289,7 +294,8 @@ class DouyinParserPlugin(MessagePluginInterface):
caption = data.get("caption") or "无标题" caption = data.get("caption") or "无标题"
author = (data.get("author") or {}) author = (data.get("author") or {})
nickname = author.get("nickname") or author.get("unique_id") or "未知作者" nickname = author.get("nickname") or author.get("unique_id") or "未知作者"
result = {"type": "video", "url": chosen_url or "", "title": caption, "author": nickname, "cover": cover_url} result = {"type": "video", "url": chosen_url or "", "title": caption, "author": nickname,
"cover": cover_url}
if result.get("url"): if result.get("url"):
return result return result
return None return None
@@ -317,10 +323,13 @@ class DouyinParserPlugin(MessagePluginInterface):
if not urls: if not urls:
return None return None
cleaned = [(u or "").strip().strip("`") for u in urls if u] cleaned = [(u or "").strip().strip("`") for u in urls if u]
def is_vx(n: str) -> bool: def is_vx(n: str) -> bool:
return bool(re.match(r"^v(3|4|5|6|7|8|9|10)(?:[\-.]|$)", n, re.I)) return bool(re.match(r"^v(3|4|5|6|7|8|9|10)(?:[\-.]|$)", n, re.I))
def is_douyinvod(n: str) -> bool: def is_douyinvod(n: str) -> bool:
return "douyinvod.com" in n.lower() return "douyinvod.com" in n.lower()
first = None first = None
for s in cleaned: for s in cleaned:
netloc = urlparse(s).netloc netloc = urlparse(s).netloc