Skip to content

Commit

Permalink
Update bot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AswanthVK authored Sep 2, 2022
1 parent cfbf3b5 commit 923116a
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
import re
import string
import asyncio
import cloudscraper
import requests
import math
import time
from datetime import timedelta
from pyrogram import Client, filters


Expand All @@ -19,23 +18,6 @@
app = Client("tgid", bot_token=TG_BOT_TOKEN, api_hash=API_HASH, api_id=APP_ID)


def mdisk(url):
api = "https://api.emilyx.in/api"
client = cloudscraper.create_scraper(allow_brotli=False)
resp = client.get(url)
if resp.status_code == 404:
return "File not found/The link you entered is wrong!"
try:
resp = client.post(api, json={"type": "mdisk", "url": url})
res = resp.json()
except BaseException:
return "API UnResponsive / Invalid Link!"
if res["success"] is True:
return res["url"]
else:
return res["msg"]


def humanbytes(size):
# https://stackoverflow.com/a/49361727/4723940
# 2**10 = 1024
Expand All @@ -50,16 +32,20 @@ def humanbytes(size):
return str(round(size, 2)) + " " + Dic_powerN[n] + 'B'


def convert(n):
return str(timedelta(seconds = n))


@app.on_message(filters.command(['start']))
async def start(client, message):
await message.reply_text(text=f"Hello 👋\n\nSend me MDisk links to convert to Direct Download Link", reply_to_message_id=message.message_id)


@app.on_message(filters.private & filters.text)
async def link_extract(bot, message):
url = message.text

if not message.text.startswith("https://mdisk"):
urls = message.text
if not message.text.startswith("https://mdisk.me"):
await message.reply_text(
f"**INVALID LINK**",
reply_to_message_id=message.message_id
Expand All @@ -70,18 +56,27 @@ async def link_extract(bot, message):
text=f"Processing…",
reply_to_message_id=message.message_id
)
inp = urls #input('Enter the Link: ')
fxl = inp.split("/")
cid = fxl[-1]
URL=f'https://diskuploader.entertainvideo.com/v1/file/cdnurl?param={cid}'
header = {
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'https://mdisk.me/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36'
}
resp = requests.get(url=URL, headers=header).json()
fn = resp['filename']
dn = resp['display_name']
dr = resp['duration']
sz = resp['size']
ht = resp['height']
wt = resp['width']
download = resp['download']

mdisk(url)
mdisk_url = mdisk(url=url)

r = requests.head(mdisk_url)
fname = None
if "Content-Disposition" in r.headers.keys():
fname = re.findall("filename=(.+)", r.headers["Content-Disposition"])[0]
file_ext_f_name = os.path.splitext(str(fname).replace('"', ""))[1]
file_size = int(requests.head(mdisk_url).headers['Content-Length'])
await a.edit_text("Title: {}\nSize: {}\n\nDL URL: {}".format(fname, humanbytes(file_size), mdisk_url))
print(mdisk(url=url))
await a.edit_text("**Title:** {}\n**Size:** {}\n**Duration:** {}\n**Resolution:** {}*{}\n**Uploader:** {}\n\n**Download Now:** {}".format(fn, humanbytes(sz), convert(dr), wt, ht, dn, download), disable_web_page_preview=True)



Expand Down

0 comments on commit 923116a

Please sign in to comment.