async def progress(current, total, event, start, type_of_ps, file_name=None): """Generic progress_callback for uploads and downloads.""" now = time.time() diff = now - start if round(diff % 10.00) == 0 or current == total: percentage = current * 100 / total speed = current / diff elapsed_time = round(diff) * 1000 time_to_completion = round((total - current) / speed) * 1000 estimated_total_time = elapsed_time + time_to_completion progress_str = "[{0}{1}] {2}%\n".format( ''.join(["▰" for i in range(math.floor(percentage / 10))]), ''.join(["▱" for i in range(10 - math.floor(percentage / 10))]), round(percentage, 2)) tmp = progress_str + \ "{0} of {1}\nETA: {2}".format( humanbytes(current), humanbytes(total), time_formatter(estimated_total_time) ) if file_name: await event.edit("{}\nFile Name: `{}`\n{}".format( type_of_ps, file_name, tmp)) else: await event.edit("{}\n{}".format(type_of_ps, tmp))
async def progress(current, total, event, start, type_of_ps, file_name=None): """Generic progress_callback for uploads and downloads.""" now = time.time() diff = now - start out_folder = TEMP_DOWNLOAD_DIRECTORY + "youtubedl/" thumb_image_path = TEMP_DOWNLOAD_DIRECTORY + "youtubedl/thumb_image.jpg" if not os.path.isdir(out_folder): os.makedirs(out_folder) if round(diff % 10.00) == 0 or current == total: percentage = current * 100 / total speed = current / diff elapsed_time = round(diff) * 1000 time_to_completion = round((total - current) / speed) * 1000 estimated_total_time = elapsed_time + time_to_completion progress_str = "{0}{1} {2}%\n".format( ''.join(["█" for i in range(math.floor(percentage / 10))]), ''.join(["░" for i in range(10 - math.floor(percentage / 10))]), round(percentage, 2)) tmp = progress_str + \ "{0} of {1}\nETA: {2}".format( humanbytes(current), humanbytes(total), time_formatter(estimated_total_time) ) if file_name: await event.edit("{}\nFile Name: `{}`\n{}".format( type_of_ps, file_name, tmp)) else: await event.edit("{}\n{}".format(type_of_ps, tmp))
async def sleepybot(time): counter = int(time.pattern_match.group(1)) await time.edit("`I am sulking and snoozing...`") if BOTLOG: str_counter = time_formatter(counter) await time.client.send_message( BOTLOG_CHATID, f"You put the bot to sleep for {str_counter}.", ) sleep(counter) await time.edit("`Okeh, Aku Terbangun Lagi!.`")
async def sleepybot(time): counter = int(time.pattern_match.group(1)) xx = await edit_or_reply(time, "`Saya mengantuk dan tertidur...`") if BOTLOG_CHATID: str_counter = time_formatter(counter) await time.client.send_message( BOTLOG_CHATID, f"**Anda menyuruh bot untuk tidur selama** {str_counter}.", ) sleep(counter) await xx.edit("**Oke, saya sudah bangun sekarang.**")
async def sleepybot(time): """ For .sleep command, let the userbot snooze for a few second. """ counter = int(time.pattern_match.group(1)) await time.edit("`I am sulking and snoozing...`") if BOTLOG: str_counter = time_formatter(counter) await time.client.send_message( BOTLOG_CHATID, f"You put the bot to sleep for {str_counter}.", ) sleep(counter) await time.edit("`OK, I'm awake now.`")
async def sleepybot(time): """For .sleep command, let the userbot snooze for a few second.""" counter = int(time.pattern_match.group(1)) await time.edit("`Saya mengantuk dan tertidur...`") if BOTLOG: str_counter = time_formatter(counter) await time.client.send_message( BOTLOG_CHATID, f"Anda menyuruh bot untuk tidur {str_counter}.", ) sleep(counter) await time.edit("**Oke, saya sudah bangun sekarang.**")
async def sleepybot(time): """ For .sleep command, let the userbot snooze for a few second. """ counter = int(time.pattern_match.group(1)) await time.edit("**Estou de mau humor e cochilando...**") if BOTLOG: str_counter = time_formatter(counter) await time.client.send_message( BOTLOG_CHATID, f"Você colocou o bot para dormir por {str_counter}.", ) sleep(counter) await time.edit("**OK, estou acordado agora.**")
async def sleepybot(time): """ Para o comando .sleep, deixe o userbot dormir por alguns segundos. """ counter = int(time.pattern_match.group(1)) await time.edit("`Estou de mau humor e cochilando.....`") if BOTLOG: str_counter = time_formatter(counter) await time.client.send_message( BOTLOG_CHATID, f"Você colocou o bot para dormir por {str_counter}.", ) sleep(counter) await time.edit("`OK, estou acordado agora.`")
async def sleepybot(time): """ For .sleep command, let the userbot snooze for a few second. """ counter = int(time.pattern_match.group(1)) await time.edit("`Saya tidur dulu King...⚡️`") if BOTLOG: str_counter = time_formatter(counter) await time.client.send_message( BOTLOG_CHATID, f"You put the bot to sleep for {str_counter}.", ) sleep(counter) await time.edit("`⚡️𝗢𝗙𝗙⚡️.`")
async def sleepybot(time): """For .sleep command, let the userbot snooze for a few second.""" counter = int(time.pattern_match.group(1)) await time.edit("`Saya tidur dulu King...⚡️`") if BOTLOG: str_counter = time_formatter(counter) await time.client.send_message( BOTLOG_CHATID, f"Anda membuat bot tidur untuk bot {str_counter}.", ) sleep(counter) await time.edit("`Oke , saya sudah bangun`")
async def arings(event): search = event.pattern_match.group(1) variables = {"search": search} response = requests.post( url, json={"query": airing_query, "variables": variables} ).json()["data"]["Media"] ms_g = f"**Name**: **{response['title']['romaji']}**(`{response['title']['native']}`)\n**ID**: `{response['id']}`" if response["nextAiringEpisode"]: airing_time = response["nextAiringEpisode"]["timeUntilAiring"] * 1000 airing_time_final = time_formatter(airing_time) ms_g += f"\n**Episode**: `{response['nextAiringEpisode']['episode']}`\n**Airing In**: `{airing_time_final}`" else: ms_g += f"\n**Episode**:{response['episodes']}\n**Status**: `N/A`" await event.edit(ms_g)
def _download_file(self, path: str, name: str, **kwargs) -> None: request = self._service.files().get_media(fileId=kwargs['id'], supportsTeamDrives=True) with io.FileIO(os.path.join(path, name), 'wb') as d_f: d_file_obj = MediaIoBaseDownload(d_f, request, chunksize=50 * 1024 * 1024) c_time = time.time() done = False while done is False: status, done = d_file_obj.next_chunk() if self._is_canceled: raise ProcessCanceled if status: f_size = status.total_size diff = time.time() - c_time downloaded = status.resumable_progress percentage = downloaded / f_size * 100 speed = round(downloaded / diff, 2) eta = round((f_size - downloaded) / speed) tmp = \ "__Downloading From GDrive...__\n" + \ "```[{}{}]({}%)```\n" + \ "× **File Name** : `{}`\n" + \ "× **File Size** : `{}`\n" + \ "× **Downloaded** : `{}`\n" + \ "× **Completed** : `{}/{}`\n" + \ "× **Speed** : `{}/s`\n" + \ "× **ETA** : `{}`" self._progress = tmp.format( "".join((Config.FINISHED_PROGRESS_STR for i in range(math.floor(percentage / 5)))), "".join( (Config.UNFINISHED_PROGRESS_STR for i in range(20 - math.floor(percentage / 5)))), round(percentage, 2), name, humanbytes(f_size), humanbytes(downloaded), self._completed, self._list, humanbytes(speed), time_formatter(eta)) self._completed += 1 _LOG.info("Downloaded Google-Drive File => Name: %s ID: %s", name, kwargs['id'])
def __progress(data: dict): if ((time() - startTime) % 4) > 3.9: if data['status'] == "downloading": eta = data.get('eta') speed = data.get('speed') if not (eta and speed): return out = "**Speed** >> {}/s\n**ETA** >> {}\n".format( humanbytes(speed), time_formatter(eta)) out += f'**File Name** >> `{data["filename"]}`\n\n' current = data.get('downloaded_bytes') total = data.get("total_bytes") if current and total: percentage = int(current) * 100 / int(total) out += f"Progress >> {int(percentage)}%\n" out += "[{}{}]".format( ''.join((Config.FINISHED_PROGRESS_STR for _ in range(floor(percentage / 5)))), ''.join((Config.UNFINISHED_PROGRESS_STR for _ in range(20 - floor(percentage / 5))))) if message.text != out: asyncio.get_event_loop().run_until_complete( message.edit(out))
def _upload_file(self, file_path: str, parent_id: str) -> str: if self._is_canceled: raise ProcessCanceled mime_type = guess_type(file_path)[0] or "text/plain" file_name = os.path.basename(file_path) body = { "name": file_name, "mimeType": mime_type, "description": "Uploaded using Userbot" } if parent_id: body["parents"] = [parent_id] if os.path.getsize(file_path) == 0: media_body = MediaFileUpload(file_path, mimetype=mime_type, resumable=False) u_file_obj = self._service.files().create( body=body, media_body=media_body, supportsTeamDrives=True).execute() file_id = u_file_obj.get("id") else: media_body = MediaFileUpload(file_path, mimetype=mime_type, chunksize=50 * 1024 * 1024, resumable=True) u_file_obj = self._service.files().create(body=body, media_body=media_body, supportsTeamDrives=True) c_time = time.time() response = None while response is None: status, response = u_file_obj.next_chunk() if self._is_canceled: raise ProcessCanceled if status: f_size = status.total_size diff = time.time() - c_time uploaded = status.resumable_progress percentage = uploaded / f_size * 100 speed = round(uploaded / diff, 2) eta = round((f_size - uploaded) / speed) tmp = \ "__Uploading to GDrive...__\n" + \ "```[{}{}]({}%)```\n" + \ "× **File Name** : `{}`\n" + \ "× **File Size** : `{}`\n" + \ "× **Uploaded** : `{}`\n" + \ "× **Completed** : `{}/{}`\n" + \ "× **Speed** : `{}/s`\n" + \ "× **ETA** : `{}`" self._progress = tmp.format( "".join((Config.FINISHED_PROGRESS_STR for i in range(math.floor(percentage / 5)))), "".join( (Config.UNFINISHED_PROGRESS_STR for i in range(20 - math.floor(percentage / 5)))), round(percentage, 2), file_name, humanbytes(f_size), humanbytes(uploaded), self._completed, self._list, humanbytes(speed), time_formatter(eta)) file_id = response.get("id") if not Config.G_DRIVE_IS_TD: self._set_permission(file_id) self._completed += 1 drive_file = self._service.files().get( fileId=file_id, fields='id, name, size', supportsTeamDrives=True).execute() file_id = drive_file.get('id') file_name = drive_file.get("name") file_size = humanbytes(int(drive_file.get('size', 0))) _LOG.info("Created Google-Drive File => Name: %s ID: %s Size: %s", file_name, file_id, file_size) return G_DRIVE_FILE_LINK.format(file_id, file_name, file_size)
def eta(self) -> str: """Returns eta""" return time_formatter((self._file_size - self._cmp_size) / self.speed if self.speed else 0)