-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"): | ||
Comment on lines
-136
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
continue | ||
try: | ||
lang = stream["tags"]["language"] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 "") | ||
) | ||
Comment on lines
-21
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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) | ||
Comment on lines
-79
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
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 "") | ||
) | ||
Comment on lines
-46
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return tmp[:-2] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
Comment on lines
-25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
download_file
refactored with the following changes:remove-pass-body
)