-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (32 loc) · 1.46 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import logging
from telegram import InlineKeyboardMarkup
from telegram.ext import Updater, CallbackQueryHandler, MessageHandler, Filters
from vid_utils import Video, BadLink
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
def get_format(bot, update):
logger.info("from {}: {}".format(update.message.chat_id, update.message.text)) # "history"
try:
video = Video(update.message.text, init_keyboard=True)
except BadLink:
update.message.reply_text("Bad link")
else:
reply_markup = InlineKeyboardMarkup(video.keyboard)
update.message.reply_text('Choose format:', reply_markup=reply_markup)
def download_choosen_format(bot, update):
query = update.callback_query
resolution_code, link = query.data.split(' ', 1)
bot.edit_message_text(text="Downloading🤞...",
chat_id=query.message.chat_id,
message_id=query.message.message_id)
video = Video(link)
video.download(resolution_code)
with video.send() as files:
for f in files:
bot.send_document(chat_id=query.message.chat_id, document=open(f, 'rb'))
token = 'YOUR TELEGRAM TOKEN'
updater = Updater(token)
updater.dispatcher.add_handler(MessageHandler(Filters.text, get_format))
updater.dispatcher.add_handler(CallbackQueryHandler(download_choosen_format))
updater.start_polling()
updater.idle()