尝试支持图文信息
This commit is contained in:
@@ -155,6 +155,9 @@ class DouyinParserPlugin(MessagePluginInterface):
|
||||
merged = self._merge_images_vertical(img_bytes_list, 1242)
|
||||
if not merged:
|
||||
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)
|
||||
return True, "发送合并图片成功"
|
||||
else:
|
||||
@@ -258,19 +261,21 @@ class DouyinParserPlugin(MessagePluginInterface):
|
||||
images_field = data.get("images") or []
|
||||
images: List[str] = []
|
||||
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)
|
||||
if chosen:
|
||||
images.append(chosen)
|
||||
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:
|
||||
return result
|
||||
return None
|
||||
video = data.get("video") or {}
|
||||
bit_rates = video.get("bit_rate") or []
|
||||
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:
|
||||
play_addr = br.get("play_addr") or {}
|
||||
urls = play_addr.get("url_list") or []
|
||||
@@ -289,7 +294,8 @@ class DouyinParserPlugin(MessagePluginInterface):
|
||||
caption = data.get("caption") or "无标题"
|
||||
author = (data.get("author") 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"):
|
||||
return result
|
||||
return None
|
||||
@@ -317,10 +323,13 @@ class DouyinParserPlugin(MessagePluginInterface):
|
||||
if not urls:
|
||||
return None
|
||||
cleaned = [(u or "").strip().strip("`") for u in urls if u]
|
||||
|
||||
def is_vx(n: str) -> bool:
|
||||
return bool(re.match(r"^v(3|4|5|6|7|8|9|10)(?:[\-.]|$)", n, re.I))
|
||||
|
||||
def is_douyinvod(n: str) -> bool:
|
||||
return "douyinvod.com" in n.lower()
|
||||
|
||||
first = None
|
||||
for s in cleaned:
|
||||
netloc = urlparse(s).netloc
|
||||
|
||||
Reference in New Issue
Block a user