From 424c47ce7403b05ad70bd8982db3859fa4845247 Mon Sep 17 00:00:00 2001 From: rking32 Date: Thu, 27 May 2021 14:58:55 +0530 Subject: [PATCH] sync to async (direct_links.py) --- userge/plugins/utils/direct_links.py | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/userge/plugins/utils/direct_links.py b/userge/plugins/utils/direct_links.py index 88def2d85..febd08318 100644 --- a/userge/plugins/utils/direct_links.py +++ b/userge/plugins/utils/direct_links.py @@ -17,7 +17,7 @@ import requests from bs4 import BeautifulSoup -from userge import userge, Message +from userge import userge, Message, pool from userge.utils import humanbytes @@ -41,28 +41,29 @@ async def direct_(message: Message): reply = "Direct Links :\n\n" for link in links: if 'drive.google.com' in link: - reply += f" 👉 {gdrive(link)}\n" + reply += f" 👉 {await gdrive(link)}\n" elif 'yadi.sk' in link: - reply += f" 👉 {yandex_disk(link)}\n" + reply += f" 👉 {await yandex_disk(link)}\n" elif 'cloud.mail.ru' in link: - reply += f" 👉 {cm_ru(link)}\n" + reply += f" 👉 {await cm_ru(link)}\n" elif 'mediafire.com' in link: - reply += f" 👉 {mediafire(link)}\n" + reply += f" 👉 {await mediafire(link)}\n" elif 'sourceforge.net' in link: - reply += f" 👉 {sourceforge(link)}\n" + reply += f" 👉 {await sourceforge(link)}\n" elif 'osdn.net' in link: - reply += f" 👉 {osdn(link)}\n" + reply += f" 👉 {await osdn(link)}\n" elif 'github.com' in link: - reply += f" 👉 {github(link)}\n" + reply += f" 👉 {await github(link)}\n" elif 'androidfilehost.com' in link: - reply += f" 👉 {androidfilehost(link)}\n" + reply += f" 👉 {await androidfilehost(link)}\n" elif "1drv.ms" in link: - reply += f" 👉 {onedrive(link)}\n" + reply += f" 👉 {await onedrive(link)}\n" else: reply += f" 👀 {link} is not supported!\n" await message.edit(reply, parse_mode="html") +@pool.run_in_thread def gdrive(url: str) -> str: """GDrive direct links generator""" drive = 'https://drive.google.com' @@ -106,6 +107,7 @@ def gdrive(url: str) -> str: return reply +@pool.run_in_thread def yandex_disk(url: str) -> str: """Yandex.Disk direct links generator Based on https://github.com/wldhx/yadisk-direct""" @@ -126,6 +128,7 @@ def yandex_disk(url: str) -> str: return reply +@pool.run_in_thread def cm_ru(url: str) -> str: """cloud.mail.ru direct links generator Using https://github.com/JrMasterModelBuilder/cmrudl.py""" @@ -150,6 +153,7 @@ def cm_ru(url: str) -> str: return reply +@pool.run_in_thread def mediafire(url: str) -> str: """MediaFire direct links generator""" try: @@ -167,6 +171,7 @@ def mediafire(url: str) -> str: return reply +@pool.run_in_thread def sourceforge(url: str) -> str: """SourceForge direct links generator""" try: @@ -188,6 +193,7 @@ def sourceforge(url: str) -> str: return reply +@pool.run_in_thread def osdn(url: str) -> str: """OSDN direct links generator""" osdn_link = 'https://osdn.net' @@ -210,6 +216,7 @@ def osdn(url: str) -> str: return reply +@pool.run_in_thread def github(url: str) -> str: """GitHub direct links generator""" try: @@ -229,6 +236,7 @@ def github(url: str) -> str: return reply +@pool.run_in_thread def androidfilehost(url: str) -> str: """AFH direct links generator""" try: @@ -280,6 +288,7 @@ def androidfilehost(url: str) -> str: return reply +@pool.run_in_thread def onedrive(link: str) -> str: link_without_query = urlparse(link)._replace(query=None).geturl() direct_link_encoded = str(standard_b64encode(bytes(link_without_query, "utf-8")), "utf-8")