Skip to content

Commit

Permalink
sync to async (direct_links.py)
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed May 27, 2021
1 parent 0a17543 commit 424c47c
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions userge/plugins/utils/direct_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -41,28 +41,29 @@ async def direct_(message: Message):
reply = "<b>Direct Links</b> :\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'
Expand Down Expand Up @@ -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"""
Expand All @@ -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"""
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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'
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 424c47c

Please sign in to comment.