def update_all_messages():
    msg = get_readable_message()
    msg += f"<b>๐Ÿ–ฅ๏ธ CPU:</b> {psutil.cpu_percent()}%\n" \
           f"<b>๐Ÿš€ RAM:</b> {psutil.virtual_memory().percent}%\n" \
           f"<b>๐Ÿ“ฆ DISK:</b> {psutil.disk_usage('/').percent}%\n"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        dlspeed = get_readable_file_size(dlspeed_bytes)
        ulspeed = get_readable_file_size(uldl_bytes)
        msg += f"\n<b>DL:</b>{dlspeed}ps ๐Ÿ”ป| <b>UL:</b>{ulspeed}ps ๐Ÿ”บ\n"
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[
                    chat_id] and msg != status_reply_dict[chat_id].text:
                if len(msg) == 0:
                    msg = "Starting DL"
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
def sendStatusMessage(msg, bot):
    progress = get_readable_message()
    progress += f"<b>๐Ÿ–ฅ CPU:</b> {psutil.cpu_percent()}%\n" \
           f"<b>๐Ÿš€ RAM:</b> {psutil.virtual_memory().percent}%\n" \
           f"<b>๐Ÿ“ฆ DISK:</b> {psutil.disk_usage('/').percent}%\n"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        dlspeed = get_readable_file_size(dlspeed_bytes)
        ulspeed = get_readable_file_size(uldl_bytes)
        progress += f"\n<b>DL:</b>{dlspeed}ps ๐Ÿ”ป| <b>UL:</b>{ulspeed}ps ๐Ÿ”บ\n"
    with status_reply_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as e:
                LOGGER.error(str(e))
                del status_reply_dict[msg.message.chat.id]
        message = sendMessage(progress, bot, msg)
        status_reply_dict[msg.message.chat.id] = message
def get_readable_message():
    with download_dict_lock:
        msg = "โœฅโ•โ•โ•โ• @๐๐ซ๐ข๐ข๐ข๐ข๐ฒ๐จ๐๐Ž๐“๐ฌ โ•โ•โ•โ•โœฅ"
        for download in list(download_dict.values()):
            msg += f"<b>\n\n๐Ÿ—‚ ๐—™๐—ถ๐—น๐—ฒ๐—ก๐—ฎ๐—บ๐—ฒ : </b> <code>{download.name()}</code>"
            msg += f"\n<b>๐Ÿšฆ ๐’๐ญ๐š๐ญ๐ฎ๐ฌ : </b> <i>{download.status()}</i>"
            if download.status(
            ) != MirrorStatus.STATUS_ARCHIVING and download.status(
            ) != MirrorStatus.STATUS_EXTRACTING:
                msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code>"
                if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                    msg += f"\n<b>๐Ÿ“ฅ ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐๐ž๐ : </b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
                else:
                    msg += f"\n<b>๐Ÿ“ค ๐”๐ฉ๐ฅ๐จ๐š๐๐ž๐ : </b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
                msg += f"\n<b>๐Ÿš€ ๐’๐ฉ๐ž๐ž๐ : </b> {download.speed()}, \n<b>โณ ๐„๐“๐€ : </b> {download.eta()} "
                # if hasattr(download, 'is_torrent'):
                try:
                    msg += f"\n<b>โš“๏ธ ๐ˆ๐ง๐Ÿ๐จ : -Seeders:</b> {download.aria_download().num_seeders}" \
                        f" | <b>๐Ÿ”„ ๐๐ž๐ž๐ซ๐ฌ : </b> {download.aria_download().connections}"
                except:
                    pass
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                msg += f"\n<b>๐Ÿšซ ๐“๐จ ๐’๐ญ๐จ๐ฉ : </b> <code>/{BotCommands.CancelMirror} {download.gid()}</code>"
            msg += "\n\n"
        return msg
Example #4
0
def getDownloadByGid(gid):
    with download_dict_lock:
        for dl in download_dict.values():
            status = dl.status()
            if status != MirrorStatus.STATUS_UPLOADING and status != MirrorStatus.STATUS_ARCHIVING \
                    and status != MirrorStatus.STATUS_EXTRACTING:
                if dl.gid() == gid:
                    return dl
    return None
Example #5
0
def cancel_all(update, context):
    with download_dict_lock:
        count = 0
        for dlDetails in list(download_dict.values()):
            if dlDetails.status() == MirrorStatus.STATUS_DOWNLOADING \
                    or dlDetails.status() == MirrorStatus.STATUS_WAITING:
                dlDetails.download().cancel_download()
                count += 1
    delete_all_messages()
    sendMessage(f'Cancelled {count} downloads!', context.bot, update)
Example #6
0
def update_all_messages():
    total, used, free = shutil.disk_usage('.')
    used = get_readable_file_size(used)
    free = get_readable_file_size(free)
    msg = get_readable_message()
    msg += f"<b>๐Ÿ–ฅ๏ธ CPU:</b> {psutil.cpu_percent()}%" \
           f"<b>๐Ÿš€ RAM:</b> {psutil.virtual_memory().percent}%" \
           f"<b>๐Ÿ“ฆ DISK:</b> {psutil.disk_usage('/').percent}%"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        dlspeed = get_readable_file_size(dlspeed_bytes)
        ulspeed = get_readable_file_size(uldl_bytes)
        msg += f"\n<b>USED:</b> {used} | <b>FREE:</b> {free}\n<b>DL:</b> {dlspeed}ps ๐Ÿ”ป | <b>UL:</b> {ulspeed}ps ๐Ÿ”บ\n"
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[
                    chat_id] and msg != status_reply_dict[chat_id].text:
                if len(msg) == 0:
                    msg = "Starting DL"
                try:
                    keyboard = [[
                        InlineKeyboardButton("๐Ÿ”„ REFRESH ๐Ÿ”„",
                                             callback_data=str(ONE)),
                        InlineKeyboardButton("โŒ CLOSE โŒ",
                                             callback_data=str(TWO)),
                    ]]
                    editMessage(msg,
                                status_reply_dict[chat_id],
                                reply_markup=InlineKeyboardMarkup(keyboard))
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
def get_readable_message():
    with download_dict_lock:
        msg = "<b>โ“‚โ“โ“‰ โ“‚โ“˜โ“กโ“กโ“žโ“ก โ“โ“„โ“ƒโ’บ</b>" 
        for download in list(download_dict.values()):
            msg += f"<b>๐“ฏ๐“ฒ๐“ต๐“ฎ๐“ท๐“ช๐“ถ๐“ฎ:</b> <code>{download.name()}</code>"
            msg += f"\n<b>๐“ข๐“ฝ๐“ช๐“ฝ๐“พ๐“ผ:</b> <i>{download.status()}</i>"
            if download.status() != MirrorStatus.STATUS_ARCHIVING and download.status() != MirrorStatus.STATUS_EXTRACTING:
                msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code>"
                if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                    msg += f"\n<b>๐““๐“ธ๐”€๐“ท๐“ต๐“ธ๐“ช๐“ญ๐“ฎ๐“ญ:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
                else:
                    msg += f"\n<b>๐“ค๐“น๐“ต๐“ธ๐“ช๐“ญ๐“ฎ๐“ญ:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
                msg += f"\n<b>๐“ผ๐“น๐“ฎ๐“ฎ๐“ญ:</b> {download.speed()}, \n<b>ETA:</b> {download.eta()} "
                # if hasattr(download, 'is_torrent'):
                try:
                    msg += f"\n<b>๐“ฒ๐“ท๐“ฏ๐“ธ- ๐“ผ๐“ฎ๐“ฎ๐“ญ๐“ฎ๐“ป๐“ผ:</b> {download.aria_download().num_seeders}" \
                        f" | <b>๐“น๐“ฎ๐“ฎ๐“ป๐“ผ:</b> {download.aria_download().connections}"
                except:
                    pass
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                msg += f"\n<b>๐“ฃ๐“ธ ๐“ข๐“ฝ๐“ธ๐“น:</b> <code>/{BotCommands.CancelMirror} {download.gid()}</code>"
            msg += "\n\n"
        return msg