コード例 #1
0
def download_choosen_format(update, context):
    query = update.callback_query
    resolution_code, link = query.data.split(
        ' ', 1
    )  #setting the max parameter to 1, will return a list with 2 elements!

    context.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:
            try:
                context.bot.send_document(
                    chat_id=query.message.chat_id,
                    document=open(f,
                                  'rb'))  #open with binary file and send data
            except TimeoutError:
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text="Tansfer timeout, place try again later")
                video.remove()
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text="Finished")
        video.remove()
コード例 #2
0
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'))
コード例 #3
0
ファイル: main.py プロジェクト: abdimk/tune
def download_choosen_format(update, CallbackContext):

    query = update.callback_query
    if query == '3' or query == '1' or query == '2':
        pass
    else:
        resolution_code, link = query.data.split(' ', 1)
        b1 = b = updater.bot.edit_message_text(
            text="Making *Http* request...",
            chat_id=query.message.chat_id,
            message_id=query.message.message_id,
            parse_mode=ParseMode.MARKDOWN)
        time.sleep(2)
        b = updater.bot.edit_message_text(text="```Downloading...```",
                                          chat_id=query.message.chat_id,
                                          message_id=query.message.message_id,
                                          parse_mode=ParseMode.MARKDOWN)
        time.sleep(2)
        updater.bot.send_chat_action(chat_id=query.message.chat_id,
                                     action=ChatAction.UPLOAD_DOCUMENT)
        a = updater.bot.edit_message_text(text="```Uploading...```",
                                          chat_id=query.message.chat_id,
                                          message_id=query.message.message_id,
                                          parse_mode=ParseMode.MARKDOWN)

        video = Video(link)
        video.download(resolution_code)

        with video.send() as files:
            for f in files:
                updater.bot.send_document(
                    chat_id=query.message.chat_id,
                    document=open(f, 'rb'),
                    caption=
                    f'<b>Title</b>: {t1}\n<b>Duration</b>:<code>{d1}</code>\n<b>Views</b>:<code>{v1}</code>',
                    parse_mode=ParseMode.HTML)

        time.sleep(2)
        a.delete()
コード例 #4
0
ファイル: bot.py プロジェクト: abdimk/Riddel
def download_choosen_format(update, CallbackContext):

    query = update.callback_query
    if query == '3' or query == '1' or query == '2':
        pass
    else:
        bot = Updater(TOKEN)
        resolution_code, link = query.data.split(' ', 1)
        #b = bot.edit_message_text(text="```Downloading...```",chat_id=query.message.chat_id,message_id=query.message.message_id,parse_mode=ParseMode.MARKDOWN)
        time.sleep(2)
        # a = bot.edit_message_text(text="```Uploading...```",chat_id=query.message.chat_id,message_id=query.message.message_id,parse_mode=ParseMode.MARKDOWN)

        video = Video(link)
        video.download(resolution_code)

        with video.send() as files:
            for f in files:
                update.send_document(
                    chat_id=query.message.chat_id,
                    document=open(f, 'rb'),
                    caption=
                    f'<b>Title</b>: {t1}\n<b>Duration</b>:<code>{d1}</code>\n<b>Views</b>:<code>{v1}</code>',
                    parse_mode=ParseMode.HTML)