1+ import requests
2+ import uuid
3+ import os
4+ from pyrogram import Client , filters
5+
6+ # Created By @ImSoheilOfficial
7+ api_id = "....." # api id
8+ api_hash = "....." # api hash
9+ bot_token = "......" # توکن ربات
10+
11+ app = Client ("my_bot" , api_id = api_id , api_hash = api_hash , bot_token = bot_token )
12+
13+
14+ def get_video_url (link ):
15+ api_url = f"https://api.silohost.ir/api/api.php?link={ link } "
16+ response = requests .get (api_url )
17+ if response .status_code == 200 :
18+ data = response .json ()
19+ if data ['Status' ] == "True" :
20+ return data ['data' ]['url' ]
21+ return None
22+
23+
24+ @app .on_message (filters .text )
25+ async def handle_message (client , message ):
26+ link = message .text
27+
28+
29+ if link .startswith ("https://www.instagram.com" ) or link .startswith ("http://www.instagram.com" ):
30+ reply_message = await message .reply_text ("در حال پردازش لینک...\n لطفا منتظر بمانید!" , reply_to_message_id = message .id )
31+
32+ video_url = get_video_url (link )
33+ if video_url :
34+
35+ file_name = f"video_{ uuid .uuid4 ().hex } .mp4"
36+
37+
38+ chunk_size = 1024 * 500
39+ with requests .get (video_url , stream = True ) as r :
40+ total_size = int (r .headers .get ('content-length' , 0 ))
41+ if total_size == 0 :
42+ await reply_message .edit_text ("مشکلی در دریافت اطلاعات اندازه ویدیو پیش آمده است." )
43+ return
44+
45+ downloaded_size = 0
46+ with open (file_name , 'wb' ) as f :
47+ for chunk in r .iter_content (chunk_size = chunk_size ):
48+ f .write (chunk )
49+ downloaded_size += len (chunk )
50+ done = int (50 * downloaded_size / total_size )
51+ if downloaded_size % (500 * 1024 ) == 0 :
52+ await reply_message .edit_text (f"در حال دانلود ویدیو... { done } %" )
53+
54+
55+ await reply_message .edit_text ("دانلود کامل شد. در حال آپلود ویدیو..." )
56+ await client .send_video (chat_id = message .chat .id , video = file_name , reply_to_message_id = message .id )
57+
58+
59+ os .remove (file_name )
60+ else :
61+ await reply_message .edit_text ("مشکلی در دریافت ویدیو از لینک مورد نظر پیش آمده است." )
62+
63+ else :
64+ pass
65+
66+ if __name__ == "__main__" :
67+ app .run ()
0 commit comments