Commit 772923d

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-11-23 18:08:47
fix(twitter): handle gif media type correctly
When processing Twitter media, ensure that GIFs are treated as videos
1 parent c3d32bf
Changed files (1)
src
preview
src/preview/twitter.py
@@ -359,6 +359,8 @@ async def get_tweet_info_via_fxtwitter(url: str = "", handle: str = "", post_id:
             if variants := [x for x in x.get("variants", []) if "mp4" in x.get("content_type", "")]:
                 mp4_url = sorted(variants, key=lambda x: x.get("bitrate", 0), reverse=True)[0]["url"]
             x["url"] = mp4_url or m3u8_url
+        if x.get("type", "") == "gif":
+            x["type"] = "video"
         x["id"] = x["url"]  # record media "id" for de-duplication
     statistics = ""
     if view := glom(data, "views", default=0):
@@ -403,7 +405,7 @@ async def get_tweet_info_via_vxtwitter(url: str = "", handle: str = "", post_id:
         api_url = f"{API.VXTWITTER}/Twitter/status/{post_id}"
         logger.info(f"Twitter preview via vxtwitter: {api_url}")
         headers = {"user-agent": TELEGRAM_UA}
-        data = await hx_req(api_url, headers=headers, proxy=PROXY.TWITTER, check_kv={"user_screen_name": handle})
+        data = await hx_req(api_url, headers=headers, proxy=PROXY.TWITTER, check_kv={"tweetID": post_id})
         if data.get("hx_error"):
             logger.error("Failed to get tweet info via vxtwitter")
             return {}
@@ -415,6 +417,8 @@ async def get_tweet_info_via_vxtwitter(url: str = "", handle: str = "", post_id:
         x["id"] = x.get("url", "")  # record media "id" for de-duplication
         if x.get("type", "") == "image":  # change `image` -> `photo`
             x["type"] = "photo"
+        if x.get("type", "") == "gif":
+            x["type"] = "video"
     statistics = ""
     if view := glom(data, "views", default=0):
         statistics += f"๐Ÿ‘{readable_count(view)}"