Last active
January 2, 2021 13:29
-
-
Save muhammedfurkan/0f2ffc469903853765cb2624f14e9573 to your computer and use it in GitHub Desktop.
(https://github.com/muhammedfurkan/TelethonUserBot) telethon userbot to upload file/media https://gofile.io/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@bot.on(admin_cmd(pattern="goup ?(.*)")) | |
async def goup(event): | |
await event.edit("`Progressing`") | |
input_str = event.pattern_match.group(1) | |
reply = await event.get_reply_message() | |
if reply: | |
file_name = await event.client.download_media( | |
reply.media, | |
Config.TMP_DOWNLOAD_DIRECTORY | |
) | |
filename = os.path.basename(file_name) | |
filepath = file_name | |
await AioRequest_TGMedia(event, filepath) | |
if input_str: | |
file_name = input_str | |
filepath = file_name | |
await AioRequest_Local(event, file_name, filepath) | |
async def AioRequest_Local(event, file_name, filepath): | |
async with aiohttp.ClientSession() as session: | |
serverf='https://apiv2.gofile.io/getServer' | |
async with session.get(serverf) as r1: | |
b_server= await r1.json() | |
server=b_server['data']['server'] | |
if str(r1.status) == "200": | |
url = 'https://'+server+'.gofile.io/uploadFile' | |
files = {'file': open(filepath, 'rb'),'email':Config.GOFILE_MAIL} | |
response = await session.post(url, data=files) | |
r_server = await response.json() | |
code=r_server['data']['code'] | |
msg = "Uploaded Url: {}\n**File Name: {}".format("https://gofile.io/d/"+code,file_name) | |
await event.edit(msg) | |
r1.close() | |
async def AioRequest_TGMedia(event, filepath): | |
async with aiohttp.ClientSession() as session: | |
serverf='https://apiv2.gofile.io/getServer' | |
async with session.get(serverf) as r1: | |
b_server= await r1.json() | |
server=b_server['data']['server'] | |
if str(r1.status) == "200": | |
url = 'https://'+server+'.gofile.io/uploadFile' | |
files = {'file': open(filepath, 'rb'),'email':Config.GOFILE_MAIL} | |
response = await session.post(url, data=files) | |
r_server = await response.json() | |
code=r_server['data']['code'] | |
msg = "Uploaded Url: {}".format("https://gofile.io/d/"+code) | |
await event.edit(msg) | |
r1.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment