@@ -43,11 +43,15 @@ def check_link(message):
4343 if yt_link :
4444 global videoURL
4545 global yt
46+ global ytThumbMsg
4647
4748 videoURL = yt_link [0 ]
4849 yt = pytube .YouTube (videoURL , on_progress_callback = progressBar .progress_hook )
4950
50- bot .reply_to (message , f"Found a YouTube link: { videoURL } " , disable_web_page_preview = True )
51+ # Thumbnail With Caption
52+ # bot.reply_to(message, f"Found a YouTube link: {videoURL}", disable_web_page_preview=True)
53+ ytThumbMsg = bot .send_photo (message .chat .id , yt .thumbnail_url , caption = f"<b>{ yt .title } </b>\n \n <b>Link:</b> { videoURL } " )
54+
5155 getVidInfo (message = message )
5256
5357 else :
@@ -56,11 +60,8 @@ def check_link(message):
5660
5761# Get the available resoultuions of the video
5862def getVidInfo (message ):
59-
60- # Thumbnail With Caption
61- bot .send_photo (message .chat .id , yt .thumbnail_url , caption = f"Title: { yt .title } \n Rating: { yt .rating } \n Duration: { yt .length } " )
62-
63- bot .reply_to (message , "Looking for Available Qualities.." )
63+ global loadingMsg
64+ loadingMsg = bot .reply_to (message , "Looking for Available Qualities.." )
6465
6566 streams = yt .streams .filter (only_video = True , mime_type = "video/mp4" )
6667 streamsData = []
@@ -69,7 +70,7 @@ def getVidInfo(message):
6970 # print(count, stream.resolution, stream.filesize_mb)
7071 streamsData .append ([count , stream .resolution , stream .filesize_mb ])
7172
72- print (streamsData )
73+ # print(streamsData)
7374
7475 # Add Inline Buttons to get user input
7576 markup = types .InlineKeyboardMarkup ()
@@ -78,19 +79,20 @@ def getVidInfo(message):
7879 button = types .InlineKeyboardButton (text = f"{ data [1 ]} ─ ({ data [2 ]} MB)" , callback_data = callbackData )
7980 markup .add (button )
8081
81- bot .send_message (message .chat .id , "Choose a stream:" , reply_markup = markup )
82+ global qualityBtnList
83+ qualityBtnList = bot .send_message (message .chat .id , "Choose a stream:" , reply_markup = markup )
8284
83- # Callback handler for getVidInfo()
85+ # Callback handler for # getVidInfo()
8486@bot .callback_query_handler (func = lambda call : True )
8587def callback_query (call ):
8688 # print(call.data)
8789 received_list = call .data .split ("#" )
88- print (received_list )
90+ # print(received_list)
8991
9092 bot .answer_callback_query (call .id , f"Selected { received_list [1 ]} to download." )
9193
9294 userInput = int (received_list [0 ]) - 1
93- # downloadVideo(message=call.message, userInput=userInput)
95+ downloadVideo (message = call .message , userInput = userInput )
9496
9597
9698# Download the YouTube Video
@@ -106,9 +108,11 @@ def downloadVideo(message, userInput):
106108 # print(f"\n\n{type(userInput)}\n\n")
107109 # print(userInput)
108110
111+ bot .delete_message (chat_id = message .chat .id , message_id = qualityBtnList .message_id )
112+
109113 try :
114+ bot .edit_message_text (chat_id = message .chat .id , message_id = loadingMsg .message_id , text = "Downloading...📥" )
110115 # -------VIDEO-------
111- bot .send_message (chat_id = message .chat .id , text = "<b>Downloading...</b>📥" )
112116 streams [userInput ].download (filename = f"{ yt .title } .mp4" , output_path = mediaPath )
113117 print ("Video Downloaded." )
114118
@@ -123,17 +127,20 @@ def downloadVideo(message, userInput):
123127 except :
124128 print ("Error while downloading the Audio." )
125129
126- bot .send_message (chat_id = message .chat .id , text = "<b>Processing...♻</b>" )
130+ bot .edit_message_text (chat_id = message .chat .id , message_id = loadingMsg . message_id , text = "<b>Processing...♻</b>" )
127131
128132 # Merge the Audio & Video File
129133 vidmerge .merge (title = f"{ yt .title } " , outVidTitle = videoFileName )
130134
131- bot .send_message (chat_id = message .chat .id , text = "<b>Uploading...📤</b>" )
135+ bot .edit_message_text (chat_id = message .chat .id , message_id = loadingMsg . message_id , text = "<b>Uploading...📤</b>" )
132136
133137 # Upload the video to Telegram
134138 with open (f"vids/{ videoFileName } " , 'rb' ) as file :
135139 bot .send_document (message .chat .id , file )
140+ print ("File was uploaded/sent to the User." )
136141
142+ bot .delete_message (chat_id = message .chat .id , message_id = loadingMsg .message_id )
143+ bot .delete_message (chat_id = message .chat .id , message_id = ytThumbMsg .message_id )
137144 bot .send_message (message .chat .id , "<b>Downloaded...✅</b>" )
138145
139146 # Remove the Media Files
@@ -144,7 +151,7 @@ def deleteMedia(mediaPath, videoFileName):
144151 os .remove (f"{ mediaPath } /{ yt .title } .mp4" )
145152 os .remove (f"{ mediaPath } /{ yt .title } .mp3" )
146153 os .remove (f"{ mediaPath } /{ videoFileName } " )
147- print ("File was sent to User & Deleted from local." )
154+ print ("Media was Deleted from local." )
148155
149156
150157print ("TelegramYTDLBot is running.." )
0 commit comments