Example #1
0
async def download_coroutine(bot, session, url, file_name, chat_id, message_id,
                             start):
    CHUNK_SIZE = 2341
    downloaded = 0
    display_message = ""
    async with session.get(url,
                           timeout=Config.PROCESS_MAX_TIMEOUT) as response:
        total_length = int(response.headers["Content-Length"])
        content_type = response.headers["Content-Type"]
        if "text" in content_type and total_length < 500:
            return await response.release()
        await bot.edit_message_text(chat_id,
                                    message_id,
                                    text="""**Fetching URL**
            
URL: `{}`

Total File Size: {}""".format(url, humanbytes(total_length)))
        with open(file_name, "wb") as f_handle:
            while True:
                chunk = await response.content.read(CHUNK_SIZE)
                if not chunk:
                    break
                f_handle.write(chunk)
                downloaded += CHUNK_SIZE
                now = time.time()
                diff = now - start
                if round(diff % 5.00) == 0 or downloaded == total_length:
                    percentage = downloaded * 100 / total_length
                    set_name = os.path.basename(file_name)
                    #set_name = os.path.splitext(set_name_path)
                    speed = downloaded / diff
                    elapsed_time = round(diff) * 1000
                    time_to_completion = round(
                        (total_length - downloaded) / speed) * 1000
                    estimated_total_time = elapsed_time + time_to_completion
                    try:
                        current_message = """**Download Status..**
                        
`{}`

{} of {} done ({}%)
Speed : {}/s
ETA: {}""".format(set_name, humanbytes(downloaded), humanbytes(total_length),
                        round(percentage, 2), humanbytes(speed),
                        TimeFormatter(estimated_total_time))
                        if current_message != display_message:
                            await bot.edit_message_text(chat_id,
                                                        message_id,
                                                        text=current_message)
                            display_message = current_message
                    except Exception as e:
                        logger.info(str(e))
                        pass
        return await response.release()
Example #2
0
async def download_coroutine(bot, session, url, file_name, chat_id, message_id,
                             start):
    downloaded = 0
    display_message = ""
    async with session.get(url,
                           timeout=Config.PROCESS_MAX_TIMEOUT) as response:
        total_length = int(response.headers["Content-Length"])
        content_type = response.headers["Content-Type"]
        if "text" in content_type and total_length < 500:
            return await response.release()
        await bot.edit_message_text(chat_id,
                                    message_id,
                                    text="""Initiating Download
URL: {}
File Size: {}""".format(url, humanbytes(total_length)))
        with open(file_name, "wb") as f_handle:
            while True:
                chunk = await response.content.read(Config.CHUNK_SIZE)
                if not chunk:
                    break
                f_handle.write(chunk)
                downloaded += Config.CHUNK_SIZE
                now = time.time()
                diff = now - start
                if round(diff % 5.00) == 0 or downloaded == total_length:
                    percentage = downloaded * 100 / total_length
                    speed = downloaded / diff
                    elapsed_time = round(diff) * 1000
                    time_to_completion = round(
                        (total_length - downloaded) / speed) * 1000
                    estimated_total_time = elapsed_time + time_to_completion
                    try:
                        current_message = """**Download Status**
URL: {}
File Size: {}
Downloaded: {}
ETA: {}

©️ @Brazzers_premium_pronhub_sexy""".format(
                            url, humanbytes(total_length),
                            humanbytes(downloaded),
                            TimeFormatter(estimated_total_time))
                        if current_message != display_message:
                            await bot.edit_message_text(chat_id,
                                                        message_id,
                                                        text=current_message)
                            display_message = current_message
                    except Exception as e:
                        LOGGER.info(str(e))
                        pass
        return await response.release()
Example #3
0
async def download_coroutine(bot, session, url, file_name, chat_id, message_id,
                             start):
    downloaded = 0
    display_message = ""
    async with session.get(url,
                           timeout=Config.PROCESS_MAX_TIMEOUT) as response:
        total_length = int(response.headers["Content-Length"])
        content_type = response.headers["Content-Type"]
        if "text" in content_type and total_length < 500:
            return await response.release()
        await bot.edit_message_text(chat_id,
                                    message_id,
                                    text="""<b>○ 𝗜𝗻𝗶𝘁𝗶𝗮𝘁𝗶𝗻𝗴 𝗗𝗼𝘄𝗻𝗹𝗼𝗮𝗱</b>
<b>○ 𝗟𝗶𝗻𝗸 :</b> {}
<b>○ 𝗦𝗶𝘇𝗲 :</b> {}<b>\n\n𝗝𝗼𝗶𝗻 𝗢𝘂𝗿 𝗖𝗵𝗮𝗻𝗻𝗲𝗹 𝗙𝗼𝗿 𝗨𝗽𝗱𝗮𝘁𝗲𝘀 @FlixBots</b>""".format(
                                        url, humanbytes(total_length)))
        with open(file_name, "wb") as f_handle:
            while True:
                chunk = await response.content.read(Config.CHUNK_SIZE)
                if not chunk:
                    break
                f_handle.write(chunk)
                downloaded += Config.CHUNK_SIZE
                now = time.time()
                diff = now - start
                if round(diff % 5.00) == 0 or downloaded == total_length:
                    percentage = downloaded * 100 / total_length
                    speed = downloaded / diff
                    elapsed_time = round(diff) * 1000
                    time_to_completion = round(
                        (total_length - downloaded) / speed) * 1000
                    estimated_total_time = elapsed_time + time_to_completion
                    try:
                        current_message = """**<b>○ 𝗗𝗼𝘄𝗻𝗹𝗼𝗮𝗱 𝗦𝘁𝗮𝘁𝘂𝘀</b>**
<b>○ 𝗟𝗶𝗻𝗸 :</b> {}
<b>○ 𝗦𝗶𝘇𝗲 :</b> {}
<b>○ 𝗗𝗼𝘄𝗻𝗹𝗼𝗮𝗱𝗲𝗱 :</b> {}
<b>○ 𝗧𝗶𝗺𝗲 𝗟𝗲𝗳𝘁 :</b> {}\n\n<b>𝗝𝗼𝗶𝗻 𝗢𝘂𝗿 𝗖𝗵𝗮𝗻𝗻𝗲𝗹 𝗙𝗼𝗿 𝗨𝗽𝗱𝗮𝘁𝗲𝘀 @FlixBots</b>""".format(
                            url, humanbytes(total_length),
                            humanbytes(downloaded),
                            TimeFormatter(estimated_total_time))
                        if current_message != display_message:
                            await bot.edit_message_text(chat_id,
                                                        message_id,
                                                        text=current_message)
                            display_message = current_message
                    except Exception as e:
                        logger.info(str(e))
                        pass
        return await response.release()
Example #4
0
async def download_coroutine(bot, session, url, file_name, chat_id, message_id,
                             start):
    downloaded = 0
    display_message = ""
    async with session.get(url,
                           timeout=Config.PROCESS_MAX_TIMEOUT) as response:
        total_length = int(response.headers["Content-Length"])
        content_type = response.headers["Content-Type"]
        if "text" in content_type and total_length < 500:
            return await response.release()
        await bot.edit_message_text(chat_id,
                                    message_id,
                                    text="""Iniciando descarga...
Enlace: {}
Tamaño del archivo: {}""".format(url, humanbytes(total_length)))
        with open(file_name, "wb") as f_handle:
            while True:
                chunk = await response.content.read(Config.CHUNK_SIZE)
                if not chunk:
                    break
                f_handle.write(chunk)
                downloaded += Config.CHUNK_SIZE
                now = time.time()
                diff = now - start
                if round(diff % 5.00) == 0 or downloaded == total_length:
                    percentage = downloaded * 100 / total_length
                    speed = downloaded / diff
                    elapsed_time = round(diff) * 1000
                    time_to_completion = round(
                        (total_length - downloaded) / speed) * 1000
                    estimated_total_time = elapsed_time + time_to_completion
                    try:
                        current_message = """**Estado de la descarga**
Enlace: {}
Tamaño del archivo: {}
Archivo descargado: {}
Tiempo estimado: {}""".format(url, humanbytes(total_length),
                              humanbytes(downloaded),
                              TimeFormatter(estimated_total_time))
                        if current_message != display_message:
                            await bot.edit_message_text(chat_id,
                                                        message_id,
                                                        text=current_message)
                            display_message = current_message
                    except Exception as e:
                        logger.info(str(e))
                        pass
        return await response.release()