Commit cbff48e

benny-dou <60535774+benny-dou@users.noreply.github.com>
2026-04-14 10:39:56
style(social): update preview styles for twitter and weibo
1 parent 425979f
Changed files (3)
src/preview/twitter.py
@@ -36,7 +36,7 @@ async def preview_twitter(
     twitter_comments: bool = True,
     show_author: bool = True,
     show_pubdate: bool = True,
-    show_device: bool = True,
+    show_device: bool = False,
     show_statistics: bool = True,
     **kwargs,
 ):
@@ -136,31 +136,26 @@ async def preview_twitter(
         media_ids.add(x["id"])
         x[x["type"]] = download_file(x["url"], proxy=PROXY.TWITTER, **kwargs)
         quote_media.append(x)
-
     # 生成图片数量说明
     n_media_this = len(this_media)
     n_media_master = len(master_media) if this_info["has_master"] else 0
     n_media_quote = len(quote_media) if this_info["has_quote"] else 0
     part_strs = split_parts(n_media_master, n_media_this, n_media_quote)
-    for k, v in part_strs.items():
-        if v == "所有":
-            part_strs[k] = "图片及视频均"
 
     msg = ""
     master_handle = master_info.get("handle", "")
     # 被回复主推
     if master_info:
-        msg += "🕊**主推文内容:**"
         if true(show_author) and master_info.get("author"):
-            msg += f"\n🕊[{master_info['author']}](https://x.com/{master_info['handle']}/status/{master_info['post_id']})"
+            msg += f"\n🕊**[{master_info['author']}](https://x.com/{master_info['handle']}/status/{master_info['post_id']})**"
         if true(show_pubdate) and master_info.get("time"):
             msg += f"\n🕒{master_info['time']}"
+        if part_strs["first"]:
+            msg += f" {part_strs['first']}"
         if true(show_device) and master_info.get("device"):
             msg += f"📱{master_info['device']}"
         if true(show_statistics) and master_info.get("statistics"):
             msg += f"\n{master_info['statistics']}"
-        if part_strs["first"]:
-            msg += f"\n🏞{part_strs['first']}属于主推"
         if texts := master_info.get("texts"):
             msg += f"\n{texts}"
         if true(twitter_comments) and (comments := master_info.get("comments")):
@@ -174,20 +169,19 @@ async def preview_twitter(
 
     # 本条推文
     media.extend(this_media)
-    this_tweet_type = "跟推" if this_info["has_master"] else "本推"
     if master_info:
-        msg += f"\n🕊**{this_tweet_type}内容:**"
-
+        msg += "\n⤴️"
     if true(show_author) and this_info.get("author"):
-        msg += f"\n🕊[{this_info['author']}]({url})"
+        msg += f"\n🕊**[{this_info['author']}]({url})**"
+        msg = msg.replace("\n⤴️\n🕊", "\n⤴️")
     if true(show_pubdate) and this_info.get("time"):
         msg += f"\n🕒{this_info['time']}"
+    if part_strs["middle"] and (this_info["has_master"] or this_info["has_quote"]):  # 当有supp_info时, 附加图片数量说明
+        msg += f" {part_strs['middle']}"
     if true(show_device) and this_info.get("device"):
         msg += f"📱{this_info['device']}"
     if true(show_statistics) and this_info.get("statistics"):
         msg += f"\n{this_info['statistics']}"
-    if part_strs["middle"] and (this_info["has_master"] or this_info["has_quote"]):  # 当有supp_info时, 附加图片数量说明
-        msg += f"\n🏞{part_strs['middle']}属于{this_tweet_type}"
 
     if texts := this_info.get("texts"):
         msg += f"\n{texts}"
@@ -204,17 +198,18 @@ async def preview_twitter(
         # 有时候引用推文时会在正文末尾附带引推链接, 这里去掉
         quote_x_url = f"https://x.com/{quote_info.get('handle', '')}/status/{quote_info.get('post_id', '')}"
         msg = remove_twitter_suffix(msg, post_id=quote_info["post_id"], same_id_only=True)
-        msg += "\n🔁**引推内容:**"
+        msg += "\n//"
         if true(show_author) and quote_info.get("author"):
-            msg += f"\n🕊[{quote_info['author']}]({quote_x_url})"
+            msg += f"\n🕊**[{quote_info['author']}]({quote_x_url})**"
+            msg = msg.replace("\n//\n", "\n//")
         if true(show_pubdate) and quote_info.get("time"):
             msg += f"\n🕒{quote_info['time']}"
+        if part_strs["last"]:
+            msg += f" {part_strs['last']}"
         if true(show_device) and quote_info.get("device"):
             msg += f"📱{quote_info['device']}"
         if true(show_statistics) and quote_info.get("statistics"):
             msg += f"\n{quote_info['statistics']}"
-        if part_strs["last"]:
-            msg += f"\n🏞{part_strs['last']}属于引推"
 
         if texts := quote_info.get("texts"):
             msg += f"\n{texts}"
src/preview/weibo.py
@@ -81,9 +81,6 @@ async def preview_weibo(
     num_this = len(this_info["media"])
     num_quote = len(quote_info.get("media", []))
     part_strs = split_parts(num_this, last=num_quote)
-    for k, v in part_strs.items():
-        if v == "所有":
-            part_strs[k] = "图片及视频均"
 
     msg = ""
     if true(show_author) and this_info.get("author"):
@@ -91,43 +88,43 @@ async def preview_weibo(
 
     if true(show_pubdate) and this_info["dt"]:
         msg += f"\n🕒{this_info['dt']}"
+    if part_strs["first"] and quote_info:  # 当有quote_info时, 附加图片数量说明:
+        msg += f" {part_strs['first']}"
 
     if true(show_ip) and this_info.get("region"):
-        msg += f" 📍{this_info['region']}"
+        msg += f"\n📍{this_info['region']}"
 
     if true(show_device) and this_info.get("device"):
-        msg += f"\n📱{this_info['device']}"
+        msg += f" 📱{this_info['device']}"
 
     if true(show_statistics) and this_info.get("statistics"):
         msg += f"\n{this_info['statistics']}"
 
-    if part_strs["first"] and quote_info:  # 当有quote_info时, 附加图片数量说明:
-        msg += f"\n🏞{part_strs['first']}属于本帖"
-
     if texts := this_info.get("texts"):
         msg += f"\n{texts}"
 
     media = this_info.get("media", [])
     if quote_info:
-        msg += "\n🔁转帖内容:"
+        msg += "\n🔁"
         if true(show_author) and quote_info.get("author"):
-            msg += f"\n🧣[{quote_info['author']}](https://m.weibo.cn/detail/{quote_info['post_id']})"
+            msg += f"\n**[{quote_info['author']}](https://m.weibo.cn/detail/{quote_info['post_id']})**"
+            msg = msg.replace("\n🔁\n", "\n🔁")
 
         if true(show_pubdate) and quote_info.get("dt"):
             msg += f"\n🕒{quote_info['dt']}"
 
+        if part_strs["last"]:
+            msg += f" {part_strs['last']}"
+
         if true(show_ip) and quote_info.get("region"):
-            msg += f" 📍{quote_info['region']}"
+            msg += f"\n📍{quote_info['region']}"
 
         if true(show_device) and quote_info.get("device"):
-            msg += f"\n📱{quote_info['device']}"
+            msg += f" 📱{quote_info['device']}"
 
         if true(show_statistics) and quote_info.get("statistics"):
             msg += f"\n{quote_info['statistics']}"
 
-        if part_strs["last"]:
-            msg += f"\n🏞{part_strs['last']}属于转帖"
-
         if texts := quote_info.get("texts"):
             msg += f"\n{texts}"
 
src/utils.py
@@ -61,20 +61,17 @@ def split_parts(first: int = 0, middle: int = 0, last: int = 0) -> dict:
 
     Useful for determine the number of media files in master / reply / quote posts.
     """
-    total = first + middle + last
     data = {
-        "first": f"P1-P{first}",
-        "middle": f"P{first + 1}-P{first + middle}",
-        "last": f"P{first + middle + 1}-P{first + middle + last}",
+        "first": f"🏞P1-P{first}",
+        "middle": f"🏞P{first + 1}-P{first + middle}",
+        "last": f"🏞P{first + middle + 1}-P{first + middle + last}",
     }
     for k, v in data.items():
-        idx1, idx2 = (s.removeprefix("P") for s in v.split("-"))
+        idx1, idx2 = (s.strip("🏞P") for s in v.split("-"))
         if int(idx1) > int(idx2):
             data[k] = ""
         elif int(idx1) == int(idx2):
-            data[k] = f"P{idx1}"
-        if total > 1 and int(idx2) - int(idx1) == total - 1:
-            data[k] = "所有"
+            data[k] = f"🏞P{idx1}"
     return data
 
 
@@ -482,7 +479,7 @@ def is_supported_by_ytdlp(url: str) -> bool:
     if "t.me" in url:  # tg link
         return False
     extractors = gen_extractors()
-    extractors = [e for e in extractors if e.IE_NAME not in {"generic"}]  # filter out generic extractors
+    extractors = [e for e in extractors if e.IE_NAME != "generic"]  # filter out generic extractors
     return any(extractor.suitable(url) for extractor in extractors)