Skip to content

Commit 4db70e4

Browse files
committed
Basic Functions with User Experience. (V1)
1 parent 9f371c8 commit 4db70e4

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,4 @@ cython_debug/
163163
.mp4
164164
.mp3
165165
test.py
166-
test2.py
167-
test3.py
168166

bot.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
5862
def getVidInfo(message):
59-
60-
# Thumbnail With Caption
61-
bot.send_photo(message.chat.id, yt.thumbnail_url, caption=f"Title: {yt.title}\nRating: {yt.rating} \nDuration: {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)
8587
def 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

150157
print("TelegramYTDLBot is running..")

0 commit comments

Comments
 (0)