From 43456033b88a11b80afcae9274af35dd4a7e1bd3 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 10 Sep 2023 12:58:42 +0800 Subject: [PATCH] :bug: Add more twitter domains --- defs/fix_twitter_api.py | 10 ++++++---- models/apis/fxtwitter/model.py | 3 +++ modules/twitter_api.py | 19 ++++++++++++------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/defs/fix_twitter_api.py b/defs/fix_twitter_api.py index 7322f72..8c635bc 100644 --- a/defs/fix_twitter_api.py +++ b/defs/fix_twitter_api.py @@ -51,7 +51,7 @@ def twitter_media(tweet_media_lists: List[FixTweetMedia], text: str): if media.type == "photo": media_lists.append( InputMediaPhoto( - media.media_url, + media.url, caption=text if idx == 0 else None, parse_mode=ParseMode.HTML, ) @@ -59,15 +59,17 @@ def twitter_media(tweet_media_lists: List[FixTweetMedia], text: str): elif media.type == "gif": media_lists.append( InputMediaAnimation( - media.media_url, + media.url, caption=text if idx == 0 else None, parse_mode=ParseMode.HTML, ) ) - else: + elif media.type == "video": media_lists.append( InputMediaVideo( - media.media_url, + media.url, + thumb=media.thumbnail_url, + duration=media.duration, caption=text if idx == 0 else None, parse_mode=ParseMode.HTML, ) diff --git a/models/apis/fxtwitter/model.py b/models/apis/fxtwitter/model.py index e23b026..1462db2 100644 --- a/models/apis/fxtwitter/model.py +++ b/models/apis/fxtwitter/model.py @@ -40,6 +40,9 @@ class User(BaseModel): class FixTweetMedia(BaseModel): type: str url: str + thumbnail_url: str = "" + duration: float = 0 + format: str = "" width: int = 0 height: int = 0 altText: str = "" diff --git a/modules/twitter_api.py b/modules/twitter_api.py index a79287c..56c4830 100644 --- a/modules/twitter_api.py +++ b/modules/twitter_api.py @@ -15,34 +15,34 @@ from defs.fix_twitter_api import ( twitter_medias, ) from init import bot -from models.apis.twitter.model import MediaItem +from models.apis.fxtwitter.model import FixTweetMedia -async def send_single_tweet(message: Message, media: MediaItem, text: str, button): +async def send_single_tweet(message: Message, media: FixTweetMedia, text: str, button): if media.type == "photo": await message.reply_photo( - media.media_url, + media.url, quote=True, caption=text, reply_markup=button, ) elif media.type == "video": await message.reply_video( - media.media_url, + media.url, quote=True, caption=text, reply_markup=button, ) elif media.type == "gif": await message.reply_animation( - media.media_url, + media.url, quote=True, caption=text, reply_markup=button, ) else: await message.reply_document( - media.media_url, + media.url, quote=True, caption=text, reply_markup=button, @@ -87,7 +87,12 @@ async def process_user(message: Message, username: str): async def process_url(url: str, message: Message): url = urlparse(url) - if url.hostname and url.hostname in ["twitter.com", "vxtwitter.com"]: + if url.hostname and url.hostname in [ + "twitter.com", + "vxtwitter.com", + "fxtwitter.com", + "x.com", + ]: if url.path.find("status") >= 0: status_id = str( url.path[url.path.find("status") + 7 :].split("/")[0]