1717welcome_text = """
1818Hello there 👋
1919
20- I can download videos from X/Twitter 🐦, Pinterest 📍, Instagram 📸 and TikTok ♪. Just send me a link
20+ I can download videos from X/Twitter 🐦, Pinterest 📍, Instagram 📸, TikTok ♪ and VK . Just send me a link
2121
2222Also you can add me to a group or use me in any chat with `@QuartzMediaBot <your link>`
2323"""
@@ -32,46 +32,45 @@ async def start(message: types.Message) -> None:
3232pinterest_pattern = r"(?:https?://)?(?:www\.)?(?:\w+\.)?(?:pin\.it|pinterest\.com)/\S+"
3333instagram_pattern = r"(?:https?://)?(?:www\.)?instagram\.com/\S+"
3434tiktok_pattern = r"(?:https?://)?(?:www\.)?(?:\w+\.)?tiktok\.com/\S+"
35+ vk_pattern = r"(?:https?://)?(?:www\.)?(?:\w+\.)?vk\.(?:com|ru)/clip-\S+"
3536
36- combined_pattern = "|" .join ([twitter_pattern , pinterest_pattern , instagram_pattern , tiktok_pattern ])
37+ combined_pattern = "|" .join ([
38+ twitter_pattern ,
39+ pinterest_pattern ,
40+ instagram_pattern ,
41+ tiktok_pattern ,
42+ vk_pattern
43+ ])
3744
3845
3946@bot .message_handler (regexp = combined_pattern )
4047async def download_video (message : types .Message ) -> None :
4148 progress_msg = await bot .reply_to (message , "🔎" )
4249 try :
4350 url = re .findall (combined_pattern , message .text )[0 ]
44- video = await get_video (url )
51+ video = await get_video (url , download = True )
52+ msg = None
4553
46- if video .buffer :
47- if not video . is_image and video . has_audio :
54+ match video .content_type :
55+ case " video/mp4" :
4856 telebot .logger .debug ("Sending video" )
49- await bot .send_video (
57+ msg = await bot .send_video (
5058 message .chat .id ,
51- video = video .buffer ,
52- height = video .height ,
53- width = video .width ,
54- supports_streaming = True ,
59+ video = video .url ,
5560 reply_parameters = types .ReplyParameters (message_id = message .id )
5661 )
57- elif video .is_image :
62+ case _ if video .buffer :
5863 telebot .logger .debug ("Sending photo" )
59- await bot .send_photo (
64+ msg = await bot .send_photo (
6065 message .chat .id ,
6166 photo = video .buffer ,
6267 reply_parameters = types .ReplyParameters (message_id = message .id )
6368 )
64- elif not video .has_audio :
65- telebot .logger .debug ("Sending gif" )
66- await bot .send_animation (
67- message .chat .id ,
68- animation = video .buffer ,
69- height = video .height ,
70- width = video .width ,
71- reply_parameters = types .ReplyParameters (message_id = message .id )
72- )
73- elif message .chat .type == "private" :
74- await bot .reply_to (message , text = "It seems not to be a link to video 😔" )
69+ case _ if message .chat .type == "private" :
70+ await bot .reply_to (message , text = "It seems not to be a link to video 😔" )
71+
72+ if msg :
73+ telebot .logger .info (f"{ msg .video = } { msg .photo = } { msg .animation = } { msg .document = } " )
7574
7675 except Exception as e :
7776 telebot .logger .exception (e )
0 commit comments