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 #12

Merged
merged 1 commit into from
Jul 13, 2022
Merged

Sourcery refactored main branch #12

merged 1 commit into from
Jul 13, 2022

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jul 13, 2022

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from kalanakt July 13, 2022 12:45
Comment on lines -47 to +51
''.join(["●" for i in range(math.floor(percentage / 5))]),
''.join(["○" for i in range(20 - math.floor(percentage / 5))]),
round(percentage, 2))
''.join(["●" for _ in range(math.floor(percentage / 5))]),
''.join(["○" for _ in range(20 - math.floor(percentage / 5))]),
round(percentage, 2),
)

Copy link
Author

Choose a reason for hiding this comment

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

Function progress_for_pyrogram refactored with the following changes:

helper_funcs/display_progress.py Show resolved Hide resolved
Comment on lines -84 to +92
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 "")
)

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:

Comment on lines -18 to +31
watermarked_file = output_file + ".watermark.png"
watermarked_file = f"{output_file}.watermark.png"
metadata = extractMetadata(createParser(input_file))
width = metadata.get("width")
# https://stackoverflow.com/a/34547184/4723940
shrink_watermark_file_genertor_command = [
"ffmpeg",
"-i", water_mark_file,
"-i",
water_mark_file,
"-y -v quiet",
"-vf",
"scale={}*0.5:-1".format(width),
watermarked_file
f"scale={width}*0.5:-1",
watermarked_file,
]

Copy link
Author

Choose a reason for hiding this comment

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

Function place_water_mark refactored with the following changes:

Comment on lines -92 to +94
if os.path.lexists(out_put_file_name):
return out_put_file_name
else:
return None
return out_put_file_name if os.path.lexists(out_put_file_name) else None
Copy link
Author

Choose a reason for hiding this comment

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

Function take_screen_shot refactored with the following changes:

Copy link
Owner

Choose a reason for hiding this comment

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

thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg"
thumb_image_path = f"{Config.DOWNLOAD_LOCATION}/{str(update.from_user.id)}.jpg"
Copy link
Author

Choose a reason for hiding this comment

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

Function Gthumb01 refactored with the following changes:

Copy link
Owner

Choose a reason for hiding this comment

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

thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg"
thumb_image_path = f"{Config.DOWNLOAD_LOCATION}/{str(update.from_user.id)}.jpg"
Copy link
Author

Choose a reason for hiding this comment

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

Function Gthumb02 refactored with the following changes:

Copy link
Owner

Choose a reason for hiding this comment

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

Comment on lines -119 to +124
duration = 0
metadata = extractMetadata(createParser(download_directory))
if metadata is not None and metadata.has("duration"):
duration = metadata.get('duration').seconds

return duration
return (
metadata.get('duration').seconds
if metadata is not None and metadata.has("duration")
else 0
)
Copy link
Author

Choose a reason for hiding this comment

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

Function Mdata03 refactored with the following changes:

Comment on lines -80 to +86
tmp_directory_for_each_user = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id)
tmp_directory_for_each_user = (
f"{Config.DOWNLOAD_LOCATION}/{str(update.from_user.id)}"
)

if not os.path.isdir(tmp_directory_for_each_user):
os.makedirs(tmp_directory_for_each_user)
download_directory = tmp_directory_for_each_user + "/" + custom_file_name
download_directory = f"{tmp_directory_for_each_user}/{custom_file_name}"
Copy link
Author

Choose a reason for hiding this comment

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

Function ddl_call_back refactored with the following changes:

Comment on lines -38 to +41
save_ytdl_json_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".json"
save_ytdl_json_path = (
f"{Config.DOWNLOAD_LOCATION}/{str(update.from_user.id)}.json"
)

Copy link
Author

Choose a reason for hiding this comment

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

Function youtube_dl_call_back refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jul 13, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.66%.

Quality metrics Before After Change
Complexity 25.64 😞 25.96 😞 0.32 👎
Method Length 131.86 😞 132.03 😞 0.17 👎
Working memory 18.41 ⛔ 18.59 ⛔ 0.18 👎
Quality 36.43% 😞 35.77% 😞 -0.66% 👎
Other metrics Before After Change
Lines 1020 1025 5
Changed files Quality Before Quality After Quality Change
helper_funcs/display_progress.py 63.07% 🙂 63.44% 🙂 0.37% 👍
helper_funcs/help_Nekmo_ffmpeg.py 66.55% 🙂 66.35% 🙂 -0.20% 👎
helper_funcs/help_uploadbot.py 60.31% 🙂 58.88% 🙂 -1.43% 👎
plugins/broadcast.py 39.99% 😞 39.99% 😞 0.00%
plugins/custom_thumbnail.py 77.78% ⭐ 77.38% ⭐ -0.40% 👎
plugins/dl_button.py 17.01% ⛔ 17.01% ⛔ 0.00%
plugins/youtube_dl_button.py 5.92% ⛔ 5.92% ⛔ 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
plugins/youtube_dl_button.py youtube_dl_call_back 56 ⛔ 911 ⛔ 29 ⛔ 3.27% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
plugins/dl_button.py ddl_call_back 42 ⛔ 678 ⛔ 28 ⛔ 6.25% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
plugins/broadcast.py broadcast_ 18 🙂 284 ⛔ 16 ⛔ 28.35% 😞 Try splitting into smaller methods. Extract out complex expressions
plugins/dl_button.py download_coroutine 14 🙂 203 😞 16 ⛔ 35.96% 😞 Try splitting into smaller methods. Extract out complex expressions
helper_funcs/display_progress.py progress_for_pyrogram 6 ⭐ 155 😞 15 😞 48.59% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Copy link
Owner

@kalanakt kalanakt left a comment

Choose a reason for hiding this comment

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

Comment on lines -92 to +94
if os.path.lexists(out_put_file_name):
return out_put_file_name
else:
return None
return out_put_file_name if os.path.lexists(out_put_file_name) else None
Copy link
Owner

Choose a reason for hiding this comment

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

Comment on lines -128 to +127
if os.path.lexists(out_put_file_name):
return out_put_file_name
else:
return None
return out_put_file_name if os.path.lexists(out_put_file_name) else None
Copy link
Owner

Choose a reason for hiding this comment

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

Comment on lines -154 to +153
ss_img = await place_water_mark(ss_img, output_directory + "/" + str(time.time()) + ".jpg", wf)
ss_img = await place_water_mark(
ss_img, f"{output_directory}/{str(time.time())}.jpg", wf
)

Copy link
Owner

Choose a reason for hiding this comment

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

Comment on lines -42 to +44
text="{}: {} of {}".format(
ud_type,
humanbytes(downloaded_size),
humanbytes(total_size)
)
text=f"{ud_type}: {humanbytes(downloaded_size)} of {humanbytes(total_size)}",
)

Copy link
Owner

Choose a reason for hiding this comment

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

broadcast_id = ''.join([random.choice(string.ascii_letters) for i in range(3)])
broadcast_id = ''.join([random.choice(string.ascii_letters) for _ in range(3)])
Copy link
Owner

Choose a reason for hiding this comment

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

thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg"
thumb_image_path = f"{Config.DOWNLOAD_LOCATION}/{str(update.from_user.id)}.jpg"
Copy link
Owner

Choose a reason for hiding this comment

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

thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg"
thumb_image_path = f"{Config.DOWNLOAD_LOCATION}/{str(update.from_user.id)}.jpg"
Copy link
Owner

Choose a reason for hiding this comment

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

@kalanakt kalanakt merged commit fe101a6 into main Jul 13, 2022
@kalanakt kalanakt deleted the sourcery/main branch July 13, 2022 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant