telegram-video-downloader/main.py

44 lines
1.3 KiB
Python
Raw Normal View History

2017-07-23 10:17:25 +02:00
import logging
2017-08-09 14:49:25 +02:00
from telegram import InlineKeyboardMarkup
from telegram.ext import Updater, CallbackQueryHandler, MessageHandler, Filters
2017-08-06 15:49:22 +02:00
2017-08-09 14:49:25 +02:00
from vid_utils import Video
2017-07-23 10:17:25 +02:00
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
2017-07-23 10:17:25 +02:00
logger = logging.getLogger(__name__)
2017-08-09 14:49:25 +02:00
video = None
def get_format(bot, update):
2017-08-09 14:49:25 +02:00
logger.info(update.message.text) # "history"
global video
video = Video(update.message.text, update.message.chat_id)
2017-08-09 14:49:25 +02:00
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
2017-08-09 14:49:25 +02:00
video.download(query.data)
bot.edit_message_text(text="Downloading...",
chat_id=query.message.chat_id,
message_id=query.message.message_id)
2017-08-09 14:49:25 +02:00
with video.send() as files:
for f in files:
bot.send_document(chat_id=query.message.chat_id, document=open(f, 'rb'))
2017-08-09 14:49:25 +02:00
updater = Updater(token=YOUR_TOKEN)
2017-07-23 10:17:25 +02:00
updater.dispatcher.add_handler(MessageHandler(Filters.text, get_format))
updater.dispatcher.add_handler(CallbackQueryHandler(download_choosen_format))
2017-07-23 10:17:25 +02:00
# Start the Bot
2017-07-23 10:17:25 +02:00
updater.start_polling()
updater.idle()