From 2b990833ed748d5aa3e7db4cadff9cccbeb57815 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Mon, 15 Jan 2024 00:19:01 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- helpers/download.py | 8 ++------ helpers/download_from_url.py | 20 ++++++++++---------- helpers/progress.py | 16 +++++++++------- helpers/upload.py | 9 ++------- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/helpers/download.py b/helpers/download.py index c04a790..72659ba 100644 --- a/helpers/download.py +++ b/helpers/download.py @@ -55,9 +55,7 @@ async def download_file(client, message): stream_name = stream["codec_name"] stream_type = stream["codec_type"] codec_long_name = stream['codec_long_name'] - if stream_type in ("audio", "subtitle"): - pass - else: + if stream_type not in ("audio", "subtitle"): continue try: lang = stream["tags"]["language"] @@ -133,9 +131,7 @@ async def download_url_link(client, message): stream_name = stream["codec_name"] stream_type = stream["codec_type"] codec_long_name = stream['codec_long_name'] - if stream_type in ("audio", "subtitle"): - pass - else: + if stream_type not in ("audio", "subtitle"): continue try: lang = stream["tags"]["language"] diff --git a/helpers/download_from_url.py b/helpers/download_from_url.py index 07d63fd..58bf94c 100644 --- a/helpers/download_from_url.py +++ b/helpers/download_from_url.py @@ -18,15 +18,17 @@ def get_size(size): def time_formatter(milliseconds: int) -> str: """Inputs time in milliseconds, to get beautified time, as string""" - seconds, milliseconds = divmod(int(milliseconds), 1000) + seconds, milliseconds = divmod(milliseconds, 1000) minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) - tmp = (((str(days) + "d, ") if days else "") + - ((str(hours) + "h, ") if hours else "") + - ((str(minutes) + "m, ") if minutes else "") + - ((str(seconds) + "s, ") if seconds else "") + - ((str(milliseconds) + "ms, ") if milliseconds else "")) + tmp = ( + (f"{str(days)}d, " if days else "") + + (f"{str(hours)}h, " if hours else "") + + (f"{str(minutes)}m, " if minutes else "") + + (f"{str(seconds)}s, " if seconds else "") + + (f"{str(milliseconds)}ms, " if milliseconds else "") + ) return tmp[:-2] @@ -76,8 +78,7 @@ async def download_coroutine(session, url, file_name, event, start, bot): (total_length - downloaded) / speed) * 1000) estimated_total_time = elapsed_time + time_to_completion try: - if total_length < downloaded: - total_length = downloaded + total_length = max(total_length, downloaded) current_message = """Downloading : {}% URL: {} File Name: {} @@ -86,8 +87,7 @@ async def download_coroutine(session, url, file_name, event, start, bot): ETA: {}""".format("%.2f" % (percentage), url, file_name.split("/")[-1], humanbytes(total_length), humanbytes(downloaded), time_formatter(estimated_total_time)) - if (current_message != display_message - and current_message != "empty"): + if current_message not in [display_message, "empty"]: print(current_message) await event.edit(current_message, parse_mode=enums.ParseMode.HTML) diff --git a/helpers/progress.py b/helpers/progress.py index e126a38..86ac7a5 100644 --- a/helpers/progress.py +++ b/helpers/progress.py @@ -39,17 +39,19 @@ def humanbytes(size): while size > power: size /= power n += 1 - return str(round(size, 2)) + " " + Dic_powerN[n] + 'B' + return f"{str(round(size, 2))} {Dic_powerN[n]}B" def TimeFormatter(milliseconds: int) -> str: - seconds, milliseconds = divmod(int(milliseconds), 1000) + seconds, milliseconds = divmod(milliseconds, 1000) minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) - tmp = ((str(days) + "d, ") if days else "") + \ - ((str(hours) + "h, ") if hours else "") + \ - ((str(minutes) + "m, ") if minutes else "") + \ - ((str(seconds) + "s, ") if seconds else "") + \ - ((str(milliseconds) + "ms, ") if milliseconds else "") + tmp = ( + (f"{str(days)}d, " if days else "") + + (f"{str(hours)}h, " if hours else "") + + (f"{str(minutes)}m, " if minutes else "") + + (f"{str(seconds)}s, " if seconds else "") + + (f"{str(milliseconds)}ms, " if milliseconds else "") + ) return tmp[:-2] diff --git a/helpers/upload.py b/helpers/upload.py index 779a611..8fd31b8 100644 --- a/helpers/upload.py +++ b/helpers/upload.py @@ -22,14 +22,12 @@ async def upload_audio(client, message, file_loc): callback_data="progress_msg") ]])) - title = None artist = None thumb = None duration = 0 metadata = extractMetadata(createParser(file_loc)) - if metadata and metadata.has("title"): - title = metadata.get("title") + title = metadata.get("title") if metadata and metadata.has("title") else None if metadata and metadata.has("artist"): artist = metadata.get("artist") if metadata and metadata.has("duration"): @@ -39,10 +37,7 @@ async def upload_audio(client, message, file_loc): ex = os.path.splitext(fn)[1] fn = os.path.splitext(fn)[0] fn = os.path.splitext(fn)[0] - if ex == ".aac" or ex == ".mp3": - fn = fn + ex - else: - fn = fn + ".mka" + fn = fn + ex if ex in [".aac", ".mp3"] else f"{fn}.mka" size = os.path.getsize(file_loc) size = get_size(size)