🐛 Add more twitter domains

This commit is contained in:
xtaodada 2023-09-10 12:58:42 +08:00
parent 3015a68b64
commit 43456033b8
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 21 additions and 11 deletions

View File

@ -51,7 +51,7 @@ def twitter_media(tweet_media_lists: List[FixTweetMedia], text: str):
if media.type == "photo": if media.type == "photo":
media_lists.append( media_lists.append(
InputMediaPhoto( InputMediaPhoto(
media.media_url, media.url,
caption=text if idx == 0 else None, caption=text if idx == 0 else None,
parse_mode=ParseMode.HTML, parse_mode=ParseMode.HTML,
) )
@ -59,15 +59,17 @@ def twitter_media(tweet_media_lists: List[FixTweetMedia], text: str):
elif media.type == "gif": elif media.type == "gif":
media_lists.append( media_lists.append(
InputMediaAnimation( InputMediaAnimation(
media.media_url, media.url,
caption=text if idx == 0 else None, caption=text if idx == 0 else None,
parse_mode=ParseMode.HTML, parse_mode=ParseMode.HTML,
) )
) )
else: elif media.type == "video":
media_lists.append( media_lists.append(
InputMediaVideo( InputMediaVideo(
media.media_url, media.url,
thumb=media.thumbnail_url,
duration=media.duration,
caption=text if idx == 0 else None, caption=text if idx == 0 else None,
parse_mode=ParseMode.HTML, parse_mode=ParseMode.HTML,
) )

View File

@ -40,6 +40,9 @@ class User(BaseModel):
class FixTweetMedia(BaseModel): class FixTweetMedia(BaseModel):
type: str type: str
url: str url: str
thumbnail_url: str = ""
duration: float = 0
format: str = ""
width: int = 0 width: int = 0
height: int = 0 height: int = 0
altText: str = "" altText: str = ""

View File

@ -15,34 +15,34 @@ from defs.fix_twitter_api import (
twitter_medias, twitter_medias,
) )
from init import bot 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": if media.type == "photo":
await message.reply_photo( await message.reply_photo(
media.media_url, media.url,
quote=True, quote=True,
caption=text, caption=text,
reply_markup=button, reply_markup=button,
) )
elif media.type == "video": elif media.type == "video":
await message.reply_video( await message.reply_video(
media.media_url, media.url,
quote=True, quote=True,
caption=text, caption=text,
reply_markup=button, reply_markup=button,
) )
elif media.type == "gif": elif media.type == "gif":
await message.reply_animation( await message.reply_animation(
media.media_url, media.url,
quote=True, quote=True,
caption=text, caption=text,
reply_markup=button, reply_markup=button,
) )
else: else:
await message.reply_document( await message.reply_document(
media.media_url, media.url,
quote=True, quote=True,
caption=text, caption=text,
reply_markup=button, reply_markup=button,
@ -87,7 +87,12 @@ async def process_user(message: Message, username: str):
async def process_url(url: str, message: Message): async def process_url(url: str, message: Message):
url = urlparse(url) 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: if url.path.find("status") >= 0:
status_id = str( status_id = str(
url.path[url.path.find("status") + 7 :].split("/")[0] url.path[url.path.find("status") + 7 :].split("/")[0]