forked from samadii/WebDownloaderBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (54 loc) · 1.84 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import shutil
from web_dl import urlDownloader
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
BOT_TOKEN = os.environ.get("BOT_TOKEN","5547113554:AAH8hKnWY0KwGLSnBj7uRrDizdiAQp9b1IY")
API_ID = os.environ.get("API_ID","4682685")
API_HASH = os.environ.get("API_HASH","3eba5d471162181b8a3f7f5c0a23c307")
PORT =os.environ.get("PORT","8080")
Bot = Client(
"WebDL-Bot",
bot_token = BOT_TOKEN,
api_id = API_ID,
api_hash = API_HASH
)
START_TXT = """
Hi {}, I am Web Downloader Bot.
I can download all the components (.html, .css, img, xml, video, javascript..) from URLs.
Send any URL,
for ex: 'https://www.google.com'
"""
START_BTN = InlineKeyboardMarkup(
[[
InlineKeyboardButton('Source Code', url='https://github.com/samadii/WebDownloaderBot'),
]]
)
@Bot.on_message(filters.command(["start"]))
async def start(bot, update):
text = START_TXT.format(update.from_user.mention)
reply_markup = START_BTN
await update.reply_text(
text=text,
disable_web_page_preview=True,
reply_markup=reply_markup
)
@Bot.on_message(filters.private & filters.text & ~filters.regex('/start'))
async def webdl(_, m):
if not m.text.startswith('http'):
return await m.reply("the URL must start with 'http' or 'https'")
msg = await m.reply('Processing..')
url = m.text
name = dir = str(m.chat.id)
if not os.path.isdir(dir):
os.makedirs(dir)
obj = urlDownloader(imgFlg=True, linkFlg=True, scriptFlg=True)
res = obj.savePage(url, dir)
if not res:
return await msg.edit('something went wrong!')
shutil.make_archive(name, 'zip', base_dir=dir)
await m.reply_document(name+'.zip',caption="Your File 🗃️")
await msg.delete()
shutil.rmtree(dir)
os.remove(name+'.zip')
Bot.run()