Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions helpers/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Copy link
Author

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:

continue
try:
lang = stream["tags"]["language"]
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function download_url_link refactored with the following changes:

continue
try:
lang = stream["tags"]["language"]
Expand Down
20 changes: 10 additions & 10 deletions helpers/download_from_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function time_formatter refactored with the following changes:

return tmp[:-2]


Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function download_coroutine refactored with the following changes:

current_message = """Downloading : {}%
URL: {}
File Name: {}
Expand All @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions helpers/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function humanbytes refactored with the following changes:



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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TimeFormatter refactored with the following changes:

return tmp[:-2]
9 changes: 2 additions & 7 deletions helpers/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function upload_audio refactored with the following changes:

if metadata and metadata.has("artist"):
artist = metadata.get("artist")
if metadata and metadata.has("duration"):
Expand All @@ -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)

Expand Down