Skip to content

Comments

Unstable (Sourcery refactored)#12

Merged
StarkGang merged 1 commit intounstablefrom
sourcery/unstable
Mar 30, 2022
Merged

Unstable (Sourcery refactored)#12
StarkGang merged 1 commit intounstablefrom
sourcery/unstable

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Mar 10, 2022

Pull Request #11 refactored by Sourcery.

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

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

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 unstable branch, then run:

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

Help us improve this pull request!

Sed = ""
for match in result:
Sed += match.get_text() + "\n\n"
Sed = "".join(match.get_text() + "\n\n" for match in result)
Copy link
Author

Choose a reason for hiding this comment

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

Function _ refactored with the following changes:

  • Use str.join() instead of for loop (use-join)

Comment on lines -31 to +36
dl = 0
if total_length is None:
f.write(await r.read())
else:
total_length = int(total_length)
async for chunk in r.content.iter_chunked(max(int(total_length/500), (1024*1024)*2)):
dl = 0
async for chunk in r.content.iter_chunked(max(total_length // 500, (1024*1024)*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 download_file refactored with the following changes:

Comment on lines -88 to +102
send_as_thumb = False
if os.path.exists("./main_startup/Cache/thumb.jpg"):
send_as_thumb = True
send_as_thumb = bool(os.path.exists("./main_startup/Cache/thumb.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 send_file refactored with the following changes:

Comment on lines -206 to +218
if file_url == None:
return await s.edit(f"**Failed To GET Direct Link**")
if file_url is None:
return await s.edit("**Failed To GET Direct Link**")
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_ refactored with the following changes:

Comment on lines -38 to +41
four_x_path = '//*[@id="__next"]/main/div[2]/div[2]/div[1]/div[3]/div[4]/div[3]/div[2]/div[3]/div/button[3]'
four_x_path = '//*[@id="__next"]/main/div[2]/div[2]/div[1]/div[3]/div[4]/div[3]/div[2]/div[3]/div/button[3]'
color_used_xpath = '/html/body/div[1]/main/div[2]/div[2]/div[1]/div[1]/div/span[2]/input'
random_int = random.randint(1, 29)
value_ = "downshift-0-item-" + str(random_int)
value_ = f"downshift-0-item-{str(random_int)}"
Copy link
Author

Choose a reason for hiding this comment

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

Function make_carbon refactored with the following changes:

Comment on lines -116 to +117
return
return
if not group_call.is_connected:
await m_.edit("`Is Group Call Even Connected?`")
return
return
Copy link
Author

Choose a reason for hiding this comment

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

Function ski_p refactored with the following changes:

Comment on lines -156 to +192
input_str = get_text(message)
if not input_str:
if not message.reply_to_message:
return await u_s.edit_text("`Reply To A File To PLay It.`")
if message.reply_to_message.audio:
await u_s.edit_text("`Please Wait, Let Me Download This File!`")
audio = message.reply_to_message.audio
audio_original = await message.reply_to_message.download()
vid_title = audio.title or audio.file_name
uploade_r = message.reply_to_message.audio.performer or "Unknown Artist."
dura_ = message.reply_to_message.audio.duration
dur = datetime.timedelta(seconds=dura_)
raw_file_name = ''.join([random.choice(string.ascii_lowercase) for i in range(5)]) + ".raw"
url = message.reply_to_message.link
else:
return await u_s.edit("`Reply To A File To PLay It.`")
if input_str := get_text(message):
search = SearchVideos(str(input_str), offset=1, mode="dict", max_results=1)
rt = search.result()
result_s = rt.get("search_result")
if not result_s:
return await u_s.edit(f"`No Song Found Matching With Query - {input_str}, Please Try Giving Some Other Name.`")
url = result_s[0]["link"]
dur = result_s[0]["duration"]
vid_title = result_s[0]["title"]
yt_id = result_s[0]["id"]
uploade_r = result_s[0]["channel"]
start = time.time()
try:
audio_original = await yt_dl(url, client, message, start)
except BaseException as e:
return await u_s.edit(f"**Failed To Download** \n**Error :** `{str(e)}`")
raw_file_name = (
''.join([random.choice(string.ascii_lowercase) for _ in range(5)])
+ ".raw"
)

else:
search = SearchVideos(str(input_str), offset=1, mode="dict", max_results=1)
rt = search.result()
result_s = rt.get("search_result")
if not result_s:
return await u_s.edit(f"`No Song Found Matching With Query - {input_str}, Please Try Giving Some Other Name.`")
url = result_s[0]["link"]
dur = result_s[0]["duration"]
vid_title = result_s[0]["title"]
yt_id = result_s[0]["id"]
uploade_r = result_s[0]["channel"]
start = time.time()
try:
audio_original = await yt_dl(url, client, message, start)
except BaseException as e:
return await u_s.edit(f"**Failed To Download** \n**Error :** `{str(e)}`")
raw_file_name = ''.join([random.choice(string.ascii_lowercase) for i in range(5)]) + ".raw"
if not message.reply_to_message:
return await u_s.edit_text("`Reply To A File To PLay It.`")
if not message.reply_to_message.audio:
return await u_s.edit("`Reply To A File To PLay It.`")
await u_s.edit_text("`Please Wait, Let Me Download This File!`")
audio = message.reply_to_message.audio
audio_original = await message.reply_to_message.download()
vid_title = audio.title or audio.file_name
uploade_r = message.reply_to_message.audio.performer or "Unknown Artist."
dura_ = message.reply_to_message.audio.duration
dur = datetime.timedelta(seconds=dura_)
raw_file_name = (
''.join([random.choice(string.ascii_lowercase) for _ in range(5)])
+ ".raw"
)

url = message.reply_to_message.link
Copy link
Author

Choose a reason for hiding this comment

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

Function play_m refactored with the following changes:

Comment on lines -276 to +280
file_name = str(ytdl_data['id']) + ".mp3"
return file_name
return str(ytdl_data['id']) + ".mp3"
Copy link
Author

Choose a reason for hiding this comment

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

Function yt_dl refactored with the following changes:

Comment on lines -289 to +296
g_s_ = GPC.get((message.chat.id, client.me.id))
if g_s_:
if g_s_ := GPC.get((message.chat.id, client.me.id)):
if g_s_.is_connected:
await g_s_.stop()
del GPC[(message.chat.id, client.me.id)]
s = await edit_or_reply(message, "`Please Wait.`")
s = await edit_or_reply(message, "`Please Wait.`")
Copy link
Author

Choose a reason for hiding this comment

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

Function radio_s refactored with the following changes:

Comment on lines -325 to +330
group_call = RD_.get((message.chat.id, client.me.id))
if group_call:
if group_call.is_connected:
await group_call.stop()
else:
return await msg.edit("`Is Vc is Connected?`")
if not (group_call := RD_.get((message.chat.id, client.me.id))):
return await msg.edit("`Is Vc is Connected?`")
if group_call.is_connected:
await group_call.stop()
Copy link
Author

Choose a reason for hiding this comment

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

Function stop_radio refactored with the following changes:

Comment on lines -365 to +370
return
return
if not group_call.is_connected:
await edit_or_reply(message, "`Is Group Call Even Connected?`")
return
return
group_call.resume_playout()
await edit_or_reply(message, f"`▶️ Resumed.`")
await edit_or_reply(message, "`▶️ Resumed.`")
Copy link
Author

Choose a reason for hiding this comment

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

Function wow_dont_stop_songs refactored with the following changes:

return
await group_call.reconnect()
await edit_or_reply(message, f"`Rejoined! - Vc`")
await edit_or_reply(message, "`Rejoined! - Vc`")
Copy link
Author

Choose a reason for hiding this comment

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

Function rejoinvcpls refactored with the following changes:

return await e_.edit("`Please Give Me An Query.`")
href = await get_url(query)
if href == None:
if href is 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 m_ refactored with the following changes:

return await e_.edit("`Please Give Me An Query.`")
file_url, r_date, size, system, device = await realme_rom_search(query)
if file_url == None:
if file_url is 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 rm_s refactored with the following changes:

dur = datetime.timedelta(seconds=dur)
thumb, by, title = await shazam(music_file)
if title == None:
if title is 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 shazam_ refactored with the following changes:

dl_url = None
if download.headers:
dl_url = download.headers.get("location")
dl_url = download.headers.get("location") if download.headers 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 AnyDL.gdrive refactored with the following changes:

Comment on lines -51 to +49
if path == None:
if path is 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 AnyDL.mega_dl refactored with the following changes:

Comment on lines -47 to +57
if '/file/' in url:
url = url.replace(' ', '')
file_id = re.findall(r'\W\w\w\w\w\w\w\w\w\W', url)[0][1:-1]
id_index = re.search(file_id, url).end()
key = url[id_index + 1:]
return f'{file_id}!{key}'
elif '!' in url:
match = re.findall(r'/#!(.*)', url)
path = match[0]
return path
else:
return None
if '/file/' in url:
url = url.replace(' ', '')
file_id = re.findall(r'\W\w\w\w\w\w\w\w\w\W', url)[0][1:-1]
id_index = re.search(file_id, url).end()
key = url[id_index + 1:]
return f'{file_id}!{key}'
elif '!' in url:
match = re.findall(r'/#!(.*)', url)
return match[0]
else:
return 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 parse_url refactored with the following changes:

Comment on lines -61 to +80
path = parse_url(url).split('!')
if path == None:
return None, None, None
file_handle = path[0]
file_key = path[1]
file_key = base64_to_a32(file_key)
file_data = await api_request({
'a': 'g',
'g': 1,
'p': file_handle
})
k = (file_key[0] ^ file_key[4], file_key[1] ^ file_key[5],
file_key[2] ^ file_key[6], file_key[3] ^ file_key[7])
if 'g' not in file_data:
return None, None, None
file_url = file_data['g']
file_size = file_data['s']
attribs = base64_url_decode(file_data['at'])
attribs = decrypt_attr(attribs, k)
file_name = attribs['n']
return file_name,file_size, file_url
path = parse_url(url).split('!')
if path is None:
return None, None, None
file_handle = path[0]
file_key = path[1]
file_key = base64_to_a32(file_key)
file_data = await api_request({
'a': 'g',
'g': 1,
'p': file_handle
})
k = (file_key[0] ^ file_key[4], file_key[1] ^ file_key[5],
file_key[2] ^ file_key[6], file_key[3] ^ file_key[7])
if 'g' not in file_data:
return None, None, None
file_url = file_data['g']
file_size = file_data['s']
attribs = base64_url_decode(file_data['at'])
attribs = decrypt_attr(attribs, k)
file_name = attribs['n']
return file_name,file_size, file_url
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:

Comment on lines -87 to +86
url = f'https://g.api.mega.co.nz/cs'
url = 'https://g.api.mega.co.nz/cs'
Copy link
Author

Choose a reason for hiding this comment

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

Function api_request refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 10, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.67%.

Quality metrics Before After Change
Complexity 11.54 🙂 10.45 🙂 -1.09 👍
Method Length 106.25 🙂 105.64 🙂 -0.61 👍
Working memory 11.16 😞 11.15 😞 -0.01 👍
Quality 52.50% 🙂 53.17% 🙂 0.67% 👍
Other metrics Before After Change
Lines 1830 1831 1
Changed files Quality Before Quality After Quality Change
Cricket_info.py 83.24% ⭐ 81.53% ⭐ -1.71% 👎
any_dl.py 28.34% 😞 29.11% 😞 0.77% 👍
carbon.py 60.04% 🙂 60.00% 🙂 -0.04% 👎
cc_tools.py 69.14% 🙂 68.67% 🙂 -0.47% 👎
collage.py 23.43% ⛔ 24.26% ⛔ 0.83% 👍
fban.py 47.51% 😞 49.74% 😞 2.23% 👍
github_search.py 37.61% 😞 37.68% 😞 0.07% 👍
harem.py 80.30% ⭐ 80.08% ⭐ -0.22% 👎
imdb.py 33.73% 😞 36.88% 😞 3.15% 👍
music_player.py 54.71% 🙂 54.90% 🙂 0.19% 👍
rom_search.py 61.87% 🙂 61.87% 🙂 0.00%
shazam.py 58.65% 🙂 58.65% 🙂 0.00%
helper_files/dl_.py 68.41% 🙂 68.76% 🙂 0.35% 👍
helper_files/dl_helpers.py 81.30% ⭐ 81.50% ⭐ 0.20% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
any_dl.py download_ 36 ⛔ 473 ⛔ 22 ⛔ 10.58% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
music_player.py play_m 24 😞 479 ⛔ 17 ⛔ 19.79% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
collage.py create_s_collage 27 😞 289 ⛔ 15 😞 23.40% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
collage.py wow_collage 22 😞 298 ⛔ 16 ⛔ 25.00% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
fban.py fetch_all_fed 29 😞 196 😞 16 ⛔ 26.34% 😞 Refactor to reduce nesting. 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!

@StarkGang StarkGang merged commit 10df39d into unstable Mar 30, 2022
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