Commit 735a8be
Changed files (1)
src
preview
src/preview/weibo.py
@@ -49,9 +49,7 @@ async def preview_weibo(
weibo_comments_provider (str, optional): The weibo comments extractor: "free" or "false".
fallback (bool, optional): Fallback to other bots. Defaults to True.
"""
- if post_id.startswith("weibovideo"): # disable comments for weibo video
- weibo_comments_provider = "0"
- else:
+ if not post_id.startswith("weibovideo"):
real_post_id = real_weibo_post_id(post_id)
db_key = db_key.replace(post_id, real_post_id)
if kwargs.get("show_progress") and "progress" not in kwargs:
@@ -120,7 +118,12 @@ async def preview_weibo(
msg += f"\n{texts}"
media.extend(quote_info["media"])
- comments = await parse_weibo_comments(post_id) if true(weibo_comments_provider) else []
+
+ comments = []
+ if true(weibo_comments_provider):
+ comments = this_info.get("comments", [])
+ if not comments:
+ comments = await parse_weibo_comments(post_id)
sent_messages = await send2tg(client, message, texts=emojify(msg.strip()), media=media, comments=comments, **kwargs)
await modify_progress(del_status=True, **kwargs)
await save_messages(messages=sent_messages, key=db_key)
@@ -230,6 +233,9 @@ async def parse_weibo_video(post_id: str, **kwargs) -> dict:
info["author_url"] = f"https://m.weibo.cn/u/{data['author_id']}" if data.get("author_id") else url # for weibo video, use author profile as author url
if region := data.get("ip_info_str"): # maybe empty
info["region"] = region.removeprefix("发布于").strip()
+ if mid := data.get("mid"):
+ info["comments"] = await parse_weibo_comments(post_id=mid)
+ url = f"https://m.weibo.cn/detail/{mid}"
texts = ""
if title := data.get("title"):
texts += f"\n📝[{title}]({url})"
@@ -247,6 +253,8 @@ async def parse_weibo_video(post_id: str, **kwargs) -> dict:
@cache.memoize(ttl=30)
async def parse_weibo_comments(post_id: str) -> list[str]:
+ if not post_id:
+ return []
headers = {
"cookie": await get_weibo_cookies(),
"accept": "application/json, text/plain, */*",