Spaces:
Build error
Build error
Commit
·
0192f7e
1
Parent(s):
8d62e09
Upload 6 files
Browse files- megadl/caption.py +13 -0
- megadl/commands.py +192 -0
- megadl/forcesub.py +54 -0
- megadl/mega_dl.py +197 -0
- megadl/mega_dl1.py +197 -0
- megadl/progress.py +89 -0
megadl/caption.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# (c) Asm Safone
|
2 |
+
# A Part of MegaDL-Bot <https://github.com/AsmSafone/MegaDL-Bot>
|
3 |
+
|
4 |
+
from config import Config
|
5 |
+
from pyrogram import Client, filters
|
6 |
+
|
7 |
+
@Client.on_message(filters.reply & filters.text & filters.private & ~filters.edited)
|
8 |
+
async def caption(bot, message):
|
9 |
+
file = message.reply_to_message
|
10 |
+
if file.media and not file.video_note and not file.sticker:
|
11 |
+
await file.copy(message.chat.id, caption=message.text)
|
12 |
+
else:
|
13 |
+
return
|
megadl/commands.py
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# (c) Asm Safone
|
2 |
+
# A Part of MegaDL-Bot <https://github.com/AsmSafone/MegaDL-Bot>
|
3 |
+
|
4 |
+
import os
|
5 |
+
import math
|
6 |
+
import time
|
7 |
+
import shutil
|
8 |
+
import asyncio
|
9 |
+
import logging
|
10 |
+
from pyrogram import Client, filters
|
11 |
+
from pyrogram.errors import FloodWait, UserNotParticipant
|
12 |
+
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
13 |
+
from megadl.forcesub import handle_force_subscribe
|
14 |
+
from config import Config, TEXT
|
15 |
+
|
16 |
+
|
17 |
+
@Client.on_message(filters.command("help") & filters.private & filters.incoming)
|
18 |
+
async def help(bot, message, cb=False):
|
19 |
+
if Config.UPDATES_CHANNEL:
|
20 |
+
fsub = await handle_force_subscribe(bot, message)
|
21 |
+
if fsub == 400:
|
22 |
+
return
|
23 |
+
me = await bot.get_me()
|
24 |
+
button = [[
|
25 |
+
InlineKeyboardButton(f'🏠 HOME', callback_data='back'),
|
26 |
+
InlineKeyboardButton(f'ABOUT 👨', callback_data='about')
|
27 |
+
],[
|
28 |
+
InlineKeyboardButton(f'📦 SOURCE', url='https://github.com/imseldrith/MegaDL-Bot'),
|
29 |
+
InlineKeyboardButton(f'CLOSE 🔐', callback_data='close')
|
30 |
+
]]
|
31 |
+
reply_markup = InlineKeyboardMarkup(button)
|
32 |
+
if cb:
|
33 |
+
await message.message.edit(
|
34 |
+
text=TEXT.HELP_USER.format(bot_name=me.mention(style='md')),
|
35 |
+
disable_web_page_preview=True,
|
36 |
+
reply_markup=reply_markup
|
37 |
+
)
|
38 |
+
else:
|
39 |
+
await message.reply_text(
|
40 |
+
text=TEXT.HELP_USER.format(bot_name=me.mention(style='md')),
|
41 |
+
disable_web_page_preview=True,
|
42 |
+
reply_markup=reply_markup,
|
43 |
+
quote=True
|
44 |
+
)
|
45 |
+
|
46 |
+
|
47 |
+
@Client.on_message(filters.command("start") & filters.private & filters.incoming)
|
48 |
+
async def start(bot, message, cb=False):
|
49 |
+
if Config.UPDATES_CHANNEL:
|
50 |
+
fsub = await handle_force_subscribe(bot, message)
|
51 |
+
if fsub == 400:
|
52 |
+
return
|
53 |
+
me = await bot.get_me()
|
54 |
+
owner = await bot.get_users(Config.OWNER_ID)
|
55 |
+
owner_username = owner.username if owner.username else 'AsmSafone'
|
56 |
+
button = [[
|
57 |
+
InlineKeyboardButton(f'💡 HELP', callback_data='help'),
|
58 |
+
InlineKeyboardButton(f'ABOUT 👨', callback_data="about")
|
59 |
+
],[
|
60 |
+
InlineKeyboardButton(f'📦 SOURCE', url='https://github.com/imseldrith/MegaDL-Bot'),
|
61 |
+
InlineKeyboardButton(f'CLOSE 🔐', callback_data="close")
|
62 |
+
]]
|
63 |
+
reply_markup = InlineKeyboardMarkup(button)
|
64 |
+
if cb:
|
65 |
+
await message.message.edit(
|
66 |
+
text=TEXT.START_TEXT.format(user_mention=message.from_user.mention, bot_name=me.mention(style='md'), bot_owner=owner.mention(style="md")),
|
67 |
+
disable_web_page_preview=True,
|
68 |
+
reply_markup=reply_markup
|
69 |
+
)
|
70 |
+
else:
|
71 |
+
await message.reply_text(
|
72 |
+
text=TEXT.START_TEXT.format(user_mention=message.from_user.mention, bot_name=me.mention(style='md'), bot_owner=owner.mention(style="md")),
|
73 |
+
disable_web_page_preview=True,
|
74 |
+
reply_markup=reply_markup,
|
75 |
+
quote=True
|
76 |
+
)
|
77 |
+
|
78 |
+
|
79 |
+
@Client.on_message(filters.command("about") & filters.private & filters.incoming)
|
80 |
+
async def about(bot, message, cb=False):
|
81 |
+
if Config.UPDATES_CHANNEL:
|
82 |
+
fsub = await handle_force_subscribe(bot, message)
|
83 |
+
if fsub == 400:
|
84 |
+
return
|
85 |
+
me = await bot.get_me()
|
86 |
+
button = [[
|
87 |
+
InlineKeyboardButton(f'🏠 HOME', callback_data='back'),
|
88 |
+
InlineKeyboardButton(f'HELP 💡', callback_data='help')
|
89 |
+
],[
|
90 |
+
InlineKeyboardButton(f'📦 SOURCE', url='https://github.com/imseldrith/MegaDL-Bot'),
|
91 |
+
InlineKeyboardButton(f'CLOSE 🔐', callback_data="close")
|
92 |
+
]]
|
93 |
+
reply_markup = InlineKeyboardMarkup(button)
|
94 |
+
if cb:
|
95 |
+
await message.message.edit(
|
96 |
+
text=TEXT.ABOUT.format(bot_name=me.mention(style='md')),
|
97 |
+
disable_web_page_preview=True,
|
98 |
+
reply_markup=reply_markup
|
99 |
+
)
|
100 |
+
else:
|
101 |
+
await message.reply_text(
|
102 |
+
text=TEXT.ABOUT.format(bot_name=me.mention(style='md')),
|
103 |
+
disable_web_page_preview=True,
|
104 |
+
reply_markup=reply_markup,
|
105 |
+
quote=True
|
106 |
+
)
|
107 |
+
|
108 |
+
|
109 |
+
@Client.on_callback_query(filters.regex('^help$'))
|
110 |
+
async def help_cb(bot, message):
|
111 |
+
await message.answer()
|
112 |
+
await help(bot, message, True)
|
113 |
+
|
114 |
+
|
115 |
+
@Client.on_callback_query(filters.regex('^close$'))
|
116 |
+
async def close_cb(bot, message):
|
117 |
+
await message.message.delete()
|
118 |
+
await message.message.reply_to_message.delete()
|
119 |
+
|
120 |
+
|
121 |
+
@Client.on_callback_query(filters.regex('^back$'))
|
122 |
+
async def back_cb(bot, message):
|
123 |
+
await message.answer()
|
124 |
+
await start(bot, message, True)
|
125 |
+
|
126 |
+
|
127 |
+
@Client.on_callback_query(filters.regex('^about$'))
|
128 |
+
async def about_cb(bot, message):
|
129 |
+
await message.answer()
|
130 |
+
await about(bot, message, True)
|
131 |
+
|
132 |
+
|
133 |
+
@Client.on_callback_query(filters.regex('^refreshmeh$'))
|
134 |
+
async def refreshmeh_cb(bot, message):
|
135 |
+
if Config.UPDATES_CHANNEL:
|
136 |
+
invite_link = await bot.create_chat_invite_link(int(Config.UPDATES_CHANNEL))
|
137 |
+
try:
|
138 |
+
user = await bot.get_chat_member(int(Config.UPDATES_CHANNEL), message.from_user.id)
|
139 |
+
if user.status == "kicked":
|
140 |
+
await message.message.edit(
|
141 |
+
text="Sorry Sir, You are Banned. Contact My [Support Group](https://t.me/url_upload_bots).",
|
142 |
+
parse_mode="markdown",
|
143 |
+
disable_web_page_preview=True
|
144 |
+
)
|
145 |
+
return
|
146 |
+
except UserNotParticipant:
|
147 |
+
await message.message.edit(
|
148 |
+
text="**You Still Didn't Join ☹️, Please Join My Updates Channel To Use Me!**\n\nDue to Overload, Only Channel Subscribers Can Use Me!",
|
149 |
+
reply_markup=InlineKeyboardMarkup(
|
150 |
+
[
|
151 |
+
[
|
152 |
+
InlineKeyboardButton("🤖 Join Updates Channel 🤖", url=invite_link.invite_link)
|
153 |
+
],
|
154 |
+
[
|
155 |
+
InlineKeyboardButton("🔄 Refresh 🔄", callback_data="refreshmeh")
|
156 |
+
]
|
157 |
+
]
|
158 |
+
),
|
159 |
+
parse_mode="markdown"
|
160 |
+
)
|
161 |
+
return
|
162 |
+
except Exception:
|
163 |
+
await message.message.edit(
|
164 |
+
text="Something Went Wrong. Contact My [Support Group](https://t.me/url_upload_bots).",
|
165 |
+
parse_mode="markdown",
|
166 |
+
disable_web_page_preview=True
|
167 |
+
)
|
168 |
+
return
|
169 |
+
await message.answer()
|
170 |
+
await start(bot, message, True)
|
171 |
+
|
172 |
+
|
173 |
+
|
174 |
+
@Client.on_callback_query(filters.regex('^cancel_mega$'))
|
175 |
+
async def cancel_cb(bot, message):
|
176 |
+
basedir = Config.DOWNLOAD_LOCATION
|
177 |
+
userpath = str(message.from_user.id)
|
178 |
+
try:
|
179 |
+
await message.answer(
|
180 |
+
"Trying To Cancel... 🤒",
|
181 |
+
show_alert=True
|
182 |
+
)
|
183 |
+
await asyncio.sleep(5)
|
184 |
+
shutil.rmtree(basedir + "/" + userpath)
|
185 |
+
await message.message.delete()
|
186 |
+
await message.message.reply_text("**Process Cancelled By User 😡!**", reply_to_message_id=message.message_id)
|
187 |
+
except Exception as e:
|
188 |
+
await print(e)
|
189 |
+
await message.answer(
|
190 |
+
"Can't Cancel Right Now! 😡",
|
191 |
+
show_alert=True
|
192 |
+
)
|
megadl/forcesub.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# (c) Asm Safone
|
2 |
+
# A Part of MegaDL-Bot <https://github.com/AsmSafone/MegaDL-Bot>
|
3 |
+
|
4 |
+
import asyncio
|
5 |
+
from config import Config
|
6 |
+
from pyrogram import Client
|
7 |
+
from pyrogram.errors import FloodWait, UserNotParticipant
|
8 |
+
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
9 |
+
|
10 |
+
|
11 |
+
async def handle_force_subscribe(bot, message):
|
12 |
+
try:
|
13 |
+
invite_link = await bot.create_chat_invite_link(int(Config.UPDATES_CHANNEL))
|
14 |
+
except FloodWait as e:
|
15 |
+
await asyncio.sleep(e.x)
|
16 |
+
return 400
|
17 |
+
try:
|
18 |
+
user = await bot.get_chat_member(int(Config.UPDATES_CHANNEL), message.from_user.id)
|
19 |
+
if user.status == "kicked":
|
20 |
+
await bot.send_message(
|
21 |
+
chat_id=message.from_user.id,
|
22 |
+
text="Sorry Sir, You are Banned. Contact My [Support Group](https://t.me/AsmSupport).",
|
23 |
+
parse_mode="markdown",
|
24 |
+
disable_web_page_preview=True,
|
25 |
+
reply_to_message_id=message.message_id,
|
26 |
+
)
|
27 |
+
return 400
|
28 |
+
except UserNotParticipant:
|
29 |
+
await bot.send_message(
|
30 |
+
chat_id=message.from_user.id,
|
31 |
+
text="**Please Join My Updates Channel To Use Me!**\n\nDue to Overload, Only Channel Subscribers Can Use Me!",
|
32 |
+
reply_markup=InlineKeyboardMarkup(
|
33 |
+
[
|
34 |
+
[
|
35 |
+
InlineKeyboardButton("🤖 Join Updates Channel 🤖", url=invite_link.invite_link)
|
36 |
+
],
|
37 |
+
[
|
38 |
+
InlineKeyboardButton("🔄 Refresh 🔄", callback_data="refreshmeh")
|
39 |
+
]
|
40 |
+
]
|
41 |
+
),
|
42 |
+
parse_mode="markdown",
|
43 |
+
reply_to_message_id=message.message_id,
|
44 |
+
)
|
45 |
+
return 400
|
46 |
+
except Exception:
|
47 |
+
await bot.send_message(
|
48 |
+
chat_id=message.from_user.id,
|
49 |
+
text="Something Went Wrong. Contact My [Support Group](https://t.me/AsmSupport).",
|
50 |
+
parse_mode="markdown",
|
51 |
+
disable_web_page_preview=True,
|
52 |
+
reply_to_message_id=message.message_id,
|
53 |
+
)
|
54 |
+
return 400
|
megadl/mega_dl.py
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# (c) Asm Safone
|
2 |
+
# A Part of MegaDL-Bot <https://github.com/AsmSafone/MegaDL-Bot>
|
3 |
+
|
4 |
+
import os
|
5 |
+
import time
|
6 |
+
import shutil
|
7 |
+
import logging
|
8 |
+
import filetype
|
9 |
+
import subprocess
|
10 |
+
import moviepy.editor
|
11 |
+
from mega import Mega
|
12 |
+
from config import Config
|
13 |
+
from posixpath import join
|
14 |
+
from functools import partial
|
15 |
+
from genericpath import isfile
|
16 |
+
from hurry.filesize import size
|
17 |
+
from asyncio import get_running_loop
|
18 |
+
from pyrogram import Client, filters
|
19 |
+
from megadl.progress import progress_for_pyrogram
|
20 |
+
from megadl.forcesub import handle_force_subscribe
|
21 |
+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
22 |
+
|
23 |
+
# Logging
|
24 |
+
|
25 |
+
logging.basicConfig(level=logging.INFO,
|
26 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
27 |
+
|
28 |
+
# Mega Client
|
29 |
+
mega = Mega()
|
30 |
+
m = mega.login()
|
31 |
+
|
32 |
+
# Temp Download Directory
|
33 |
+
basedir = Config.DOWNLOAD_LOCATION
|
34 |
+
|
35 |
+
# Telegram's Max File Size
|
36 |
+
TG_MAX_FILE_SIZE = Config.TG_MAX_SIZE
|
37 |
+
|
38 |
+
# Automatic Url Detection
|
39 |
+
MEGA_REGEX = (r"^((?:https?:)?\/\/)"
|
40 |
+
r"?((?:www)\.)"
|
41 |
+
r"?((?:mega\.nz))"
|
42 |
+
r"(\/)([-a-zA-Z0-9()@:%_\+.~#?&//=]*)([\w\-]+)(\S+)?$")
|
43 |
+
|
44 |
+
# Download Mega Link
|
45 |
+
def DownloadMegaLink(url, alreadylol, download_msg):
|
46 |
+
try:
|
47 |
+
m.download_url(url, alreadylol, statusdl_msg=download_msg)
|
48 |
+
except Exception as e:
|
49 |
+
print(e)
|
50 |
+
|
51 |
+
|
52 |
+
@Client.on_message(filters.regex(MEGA_REGEX) & filters.private & filters.incoming & ~filters.edited)
|
53 |
+
async def megadl(bot, message):
|
54 |
+
if Config.UPDATES_CHANNEL:
|
55 |
+
fsub = await handle_force_subscribe(bot, message)
|
56 |
+
if fsub == 400:
|
57 |
+
return
|
58 |
+
url = message.text
|
59 |
+
user_info = f'**User ID:** #id{message.from_user.id} \n**User Name:** [{message.from_user.first_name}](tg://user?id={message.from_user.id})'
|
60 |
+
userpath = str(message.from_user.id)
|
61 |
+
alreadylol = basedir + "/" + userpath
|
62 |
+
if os.path.isdir(alreadylol):
|
63 |
+
await message.reply_text(
|
64 |
+
"**Already One Process is Going On! \nPlease Wait Until It's Get Finished 😕!**",
|
65 |
+
reply_to_message_id=message.message_id,
|
66 |
+
)
|
67 |
+
return
|
68 |
+
else:
|
69 |
+
os.makedirs(alreadylol)
|
70 |
+
try:
|
71 |
+
if 'folder' in url:
|
72 |
+
await message.reply_text(
|
73 |
+
"**Mega Folder Isn't Supported Yet 🤒!**",
|
74 |
+
reply_to_message_id=message.message_id,
|
75 |
+
)
|
76 |
+
return
|
77 |
+
else:
|
78 |
+
logs_msg = await message.forward(Config.LOG_CHANNEL)
|
79 |
+
trace_msg = await logs_msg.reply_text(f"#MegaDL: Download Started! \n\n{user_info}")
|
80 |
+
download_msg = await message.reply_text(
|
81 |
+
"**Trying To Download ...** \n\nThis Process May Take Some Time 🤷\u200d♂️!",
|
82 |
+
reply_markup=InlineKeyboardMarkup(
|
83 |
+
[
|
84 |
+
[
|
85 |
+
InlineKeyboardButton(
|
86 |
+
"Cancel Mega DL", callback_data="cancel_mega"
|
87 |
+
)
|
88 |
+
]
|
89 |
+
]
|
90 |
+
),
|
91 |
+
reply_to_message_id=message.message_id,
|
92 |
+
)
|
93 |
+
loop = get_running_loop()
|
94 |
+
await loop.run_in_executor(None, partial(DownloadMegaLink, url, alreadylol, download_msg))
|
95 |
+
getfiles = [f for f in os.listdir(alreadylol) if isfile(join(alreadylol, f))]
|
96 |
+
files = getfiles[0]
|
97 |
+
magapylol = f"{alreadylol}/{files}"
|
98 |
+
await download_msg.edit("**Downloaded Successfully 😉!**")
|
99 |
+
await trace_msg.edit(f"#MegaDL: Download Done! \n\n{user_info}")
|
100 |
+
except Exception as e:
|
101 |
+
if "list index out of range" in str(e):
|
102 |
+
await download_msg.edit("**Please Try Again After 30 Seconds 🤒!**")
|
103 |
+
await trace_msg.edit(
|
104 |
+
f"#MegaDL: Download Canceled! \nReason: `{e}` \n\n{user_info}"
|
105 |
+
)
|
106 |
+
os.system(f"kill -9 {os.getpid()} && python3 main.py")
|
107 |
+
else:
|
108 |
+
await download_msg.edit(f"**Error:** `{e}`")
|
109 |
+
await trace_msg.edit(
|
110 |
+
f"#MegaDL: Download Failed! \nReason: `{e}` \n\n{user_info}"
|
111 |
+
)
|
112 |
+
shutil.rmtree(basedir + '/' + userpath)
|
113 |
+
return
|
114 |
+
lmaocheckdis = os.stat(alreadylol).st_size
|
115 |
+
readablefilesize = size(lmaocheckdis) # Convert Bytes into readable size
|
116 |
+
if lmaocheckdis > TG_MAX_FILE_SIZE:
|
117 |
+
await download_msg.edit(f"**Detected File Size:** `{readablefilesize}` \n**Accepted File Size:** `2.0 GB` \n\nOops! File Is Too Large To Send In Telegram 🤒!")
|
118 |
+
await trace_msg.edit(f"#MegaDL: Upload Failed! \nReason: `File is Larger Than 2GB.` \n\n{user_info}")
|
119 |
+
shutil.rmtree(basedir + "/" + userpath)
|
120 |
+
return
|
121 |
+
else:
|
122 |
+
start_time = time.time()
|
123 |
+
guessedfilemime = filetype.guess(f"{magapylol}") # Detecting file type
|
124 |
+
if not guessedfilemime.mime:
|
125 |
+
await download_msg.edit("**Trying To Upload ...** \n**Can't Get File Type, Sending as Document!")
|
126 |
+
safone = await message.reply_document(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
127 |
+
await safone.reply_text(
|
128 |
+
"**Join @url_upload_bots! \nThanks For Using Me 😘!**",
|
129 |
+
reply_markup=InlineKeyboardMarkup(
|
130 |
+
[
|
131 |
+
[
|
132 |
+
InlineKeyboardButton(
|
133 |
+
"🙌 SHARE 🙌",
|
134 |
+
url="https://t.me/share/url?url=Hey%20Guys!%20%20Check%20Out%20@imseldrith%20's%20Bots%20Channel.%20%20Share%20His%20Bots%20And%20Support%20Him%20%F0%9F%98%89!%20%20Here%20Is%20The%20Bots%20Channel:-%20https://t.me/url_upload_bots",
|
135 |
+
)
|
136 |
+
]
|
137 |
+
]
|
138 |
+
),
|
139 |
+
reply_to_message_id=safone.message_id,
|
140 |
+
)
|
141 |
+
await download_msg.delete()
|
142 |
+
await trace_msg.edit(f"#MegaDL: Upload Done! \n\n{user_info}")
|
143 |
+
shutil.rmtree(basedir + "/" + userpath)
|
144 |
+
return
|
145 |
+
# Checking file type
|
146 |
+
filemimespotted = guessedfilemime.mime
|
147 |
+
await download_msg.edit("**Trying To Upload ...**")
|
148 |
+
if "image/gif" in filemimespotted:
|
149 |
+
safone = await message.reply_animation(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
150 |
+
elif "image" in filemimespotted:
|
151 |
+
safone = await message.reply_photo(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
152 |
+
elif "video" in filemimespotted:
|
153 |
+
viddura = moviepy.editor.VideoFileClip(f"{magapylol}")
|
154 |
+
vidduration = int(viddura.duration)
|
155 |
+
thumbnail_path = f"{alreadylol}/thumbnail.jpg"
|
156 |
+
subprocess.call(['ffmpeg', '-i', magapylol, '-ss', '00:00:10.000', '-vframes', '1', thumbnail_path])
|
157 |
+
safone = await message.reply_video(magapylol, duration=vidduration, thumb=thumbnail_path, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
158 |
+
elif "audio" in filemimespotted:
|
159 |
+
safone = await message.reply_audio(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
160 |
+
else:
|
161 |
+
safone = await message.reply_document(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
162 |
+
await safone.reply_text(
|
163 |
+
"**Join @url_upload_bots! \nThanks For Using Me 😘!**",
|
164 |
+
reply_markup=InlineKeyboardMarkup(
|
165 |
+
[
|
166 |
+
[
|
167 |
+
InlineKeyboardButton(
|
168 |
+
"🙌 SHARE 🙌",
|
169 |
+
url="https://t.me/share/url?url=Hey%20Guys!%20%20Check%20Out%20@imseldrith%20's%20Bots%20Channel.%20%20Share%20His%20Bots%20And%20Support%20Him%20%F0%9F%98%89!%20%20Here%20Is%20The%20Channel:-%20https://t.me/url_upload_bots",
|
170 |
+
)
|
171 |
+
]
|
172 |
+
]
|
173 |
+
),
|
174 |
+
reply_to_message_id=safone.message_id,
|
175 |
+
)
|
176 |
+
await download_msg.delete()
|
177 |
+
await trace_msg.edit(f"#MegaDL: Upload Done! \n\n{user_info}")
|
178 |
+
try:
|
179 |
+
shutil.rmtree(basedir + "/" + userpath)
|
180 |
+
print("[ MegaDL-Bot ] Successfully Cleaned Temp Download Directory!")
|
181 |
+
except Exception as e:
|
182 |
+
print(e)
|
183 |
+
return
|
184 |
+
|
185 |
+
@Client.on_message(filters.command("cancel") & filters.private & filters.incoming & ~filters.edited)
|
186 |
+
async def cancel_dl(bot, message):
|
187 |
+
if Config.UPDATES_CHANNEL:
|
188 |
+
fsub = await handle_force_subscribe(bot, message)
|
189 |
+
if fsub == 400:
|
190 |
+
return
|
191 |
+
userpath = str(message.from_user.id)
|
192 |
+
try:
|
193 |
+
shutil.rmtree(basedir + "/" + userpath)
|
194 |
+
await message.reply_text("✅ **Downloading Canceled Successfully!**", reply_to_message_id=message.message_id)
|
195 |
+
except Exception as e:
|
196 |
+
await print(e)
|
197 |
+
await message.reply_text("❌ **No Active Download Process To Cancel!**", reply_to_message_id=message.message_id)
|
megadl/mega_dl1.py
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# (c) Asm Safone
|
2 |
+
# A Part of MegaDL-Bot <https://github.com/AsmSafone/MegaDL-Bot>
|
3 |
+
|
4 |
+
import os
|
5 |
+
import time
|
6 |
+
import shutil
|
7 |
+
import logging
|
8 |
+
import filetype
|
9 |
+
import subprocess
|
10 |
+
import moviepy.editor
|
11 |
+
from mega import Mega
|
12 |
+
from config import Config
|
13 |
+
from posixpath import join
|
14 |
+
from functools import partial
|
15 |
+
from genericpath import isfile
|
16 |
+
from hurry.filesize import size
|
17 |
+
from asyncio import get_running_loop
|
18 |
+
from pyrogram import Client, filters
|
19 |
+
from megadl.progress import progress_for_pyrogram
|
20 |
+
from megadl.forcesub import handle_force_subscribe
|
21 |
+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
22 |
+
|
23 |
+
# Logging
|
24 |
+
|
25 |
+
logging.basicConfig(level=logging.INFO,
|
26 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
27 |
+
|
28 |
+
# Mega Client
|
29 |
+
mega = Mega()
|
30 |
+
m = mega.login()
|
31 |
+
|
32 |
+
# Temp Download Directory
|
33 |
+
basedir = Config.DOWNLOAD_LOCATION
|
34 |
+
|
35 |
+
# Telegram's Max File Size
|
36 |
+
TG_MAX_FILE_SIZE = Config.TG_MAX_SIZE
|
37 |
+
|
38 |
+
# Automatic Url Detection
|
39 |
+
MEGA_REGEX = (r"^((?:https?:)?\/\/)"
|
40 |
+
r"?((?:www)\.)"
|
41 |
+
r"?((?:mega\.nz))"
|
42 |
+
r"(\/)([-a-zA-Z0-9()@:%_\+.~#?&//=]*)([\w\-]+)(\S+)?$")
|
43 |
+
|
44 |
+
# Download Mega Link
|
45 |
+
def DownloadMegaLink(url, alreadylol, download_msg):
|
46 |
+
try:
|
47 |
+
m.download_url(url, alreadylol, statusdl_msg=download_msg)
|
48 |
+
except Exception as e:
|
49 |
+
print(e)
|
50 |
+
|
51 |
+
|
52 |
+
@Client.on_message(filters.regex(MEGA_REGEX) & filters.private & filters.incoming & ~filters.edited)
|
53 |
+
async def megadl(bot, message):
|
54 |
+
if Config.UPDATES_CHANNEL:
|
55 |
+
fsub = await handle_force_subscribe(bot, message)
|
56 |
+
if fsub == 400:
|
57 |
+
return
|
58 |
+
url = message.text
|
59 |
+
user_info = f'**User ID:** #id{message.from_user.id} \n**User Name:** [{message.from_user.first_name}](tg://user?id={message.from_user.id})'
|
60 |
+
userpath = str(message.from_user.id)
|
61 |
+
alreadylol = basedir + "/" + userpath
|
62 |
+
if os.path.isdir(alreadylol):
|
63 |
+
await message.reply_text(
|
64 |
+
"**Already One Process is Going On! \nPlease Wait Until It's Get Finished 😕!**",
|
65 |
+
reply_to_message_id=message.message_id,
|
66 |
+
)
|
67 |
+
return
|
68 |
+
else:
|
69 |
+
os.makedirs(alreadylol)
|
70 |
+
try:
|
71 |
+
if 'folder' in url:
|
72 |
+
await message.reply_text(
|
73 |
+
"**Mega Folder Isn't Supported Yet 🤒!**",
|
74 |
+
reply_to_message_id=message.message_id,
|
75 |
+
)
|
76 |
+
return
|
77 |
+
else:
|
78 |
+
logs_msg = await message.forward(Config.LOG_CHANNEL)
|
79 |
+
trace_msg = await logs_msg.reply_text(f"#MegaDL: Download Started! \n\n{user_info}")
|
80 |
+
download_msg = await message.reply_text(
|
81 |
+
"**Trying To Download ...** \n\nThis Process May Take Some Time 🤷\u200d♂️!",
|
82 |
+
reply_markup=InlineKeyboardMarkup(
|
83 |
+
[
|
84 |
+
[
|
85 |
+
InlineKeyboardButton(
|
86 |
+
"Cancel Mega DL", callback_data="cancel_mega"
|
87 |
+
)
|
88 |
+
]
|
89 |
+
]
|
90 |
+
),
|
91 |
+
reply_to_message_id=message.message_id,
|
92 |
+
)
|
93 |
+
loop = get_running_loop()
|
94 |
+
await loop.run_in_executor(None, partial(DownloadMegaLink, url, alreadylol, download_msg))
|
95 |
+
getfiles = [f for f in os.listdir(alreadylol) if isfile(join(alreadylol, f))]
|
96 |
+
files = getfiles[0]
|
97 |
+
magapylol = f"{alreadylol}/{files}"
|
98 |
+
await download_msg.edit("**Downloaded Successfully 😉!**")
|
99 |
+
await trace_msg.edit(f"#MegaDL: Download Done! \n\n{user_info}")
|
100 |
+
except Exception as e:
|
101 |
+
if "list index out of range" in str(e):
|
102 |
+
await download_msg.edit("**Please Try Again After 30 Seconds 🤒!**")
|
103 |
+
await trace_msg.edit(
|
104 |
+
f"#MegaDL: Download Canceled! \nReason: `{e}` \n\n{user_info}"
|
105 |
+
)
|
106 |
+
os.system(f"kill -9 {os.getpid()} && python3 main.py")
|
107 |
+
else:
|
108 |
+
await download_msg.edit(f"**Error:** `{e}`")
|
109 |
+
await trace_msg.edit(
|
110 |
+
f"#MegaDL: Download Failed! \nReason: `{e}` \n\n{user_info}"
|
111 |
+
)
|
112 |
+
shutil.rmtree(basedir + '/' + userpath)
|
113 |
+
return
|
114 |
+
lmaocheckdis = os.stat(alreadylol).st_size
|
115 |
+
readablefilesize = size(lmaocheckdis) # Convert Bytes into readable size
|
116 |
+
if lmaocheckdis > TG_MAX_FILE_SIZE:
|
117 |
+
await download_msg.edit(f"**Detected File Size:** `{readablefilesize}` \n**Accepted File Size:** `2.0 GB` \n\nOops! File Is Too Large To Send In Telegram 🤒!")
|
118 |
+
await trace_msg.edit(f"#MegaDL: Upload Failed! \nReason: `File is Larger Than 2GB.` \n\n{user_info}")
|
119 |
+
shutil.rmtree(basedir + "/" + userpath)
|
120 |
+
return
|
121 |
+
else:
|
122 |
+
start_time = time.time()
|
123 |
+
guessedfilemime = filetype.guess(f"{magapylol}") # Detecting file type
|
124 |
+
if not guessedfilemime.mime:
|
125 |
+
await download_msg.edit("**Trying To Upload ...** \n**Can't Get File Type, Sending as Document!")
|
126 |
+
safone = await message.reply_document(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
127 |
+
await safone.reply_text(
|
128 |
+
"**Join @url_upload_bots ! \nThanks For Using Me 😘!**",
|
129 |
+
reply_markup=InlineKeyboardMarkup(
|
130 |
+
[
|
131 |
+
[
|
132 |
+
InlineKeyboardButton(
|
133 |
+
"🙌 SHARE 🙌",
|
134 |
+
url="https://t.me/share/url?url=**Hey%20Guys!%20%20Check%20Out%20@imseldrith%20Bots%20Channel.%20%20Share%20His%20Bots%20And%20Support%20Him%20%F0%9F%98%89!%20%20Here%20Is%20The%20Bots%20List%20:-%20https://t.me/url_upload_bots **",
|
135 |
+
)
|
136 |
+
]
|
137 |
+
]
|
138 |
+
),
|
139 |
+
reply_to_message_id=safone.message_id,
|
140 |
+
)
|
141 |
+
await download_msg.delete()
|
142 |
+
await trace_msg.edit(f"#MegaDL: Upload Done! \n\n{user_info}")
|
143 |
+
shutil.rmtree(basedir + "/" + userpath)
|
144 |
+
return
|
145 |
+
# Checking file type
|
146 |
+
filemimespotted = guessedfilemime.mime
|
147 |
+
await download_msg.edit("**Trying To Upload ...**")
|
148 |
+
if "image/gif" in filemimespotted:
|
149 |
+
safone = await message.reply_animation(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
150 |
+
elif "image" in filemimespotted:
|
151 |
+
safone = await message.reply_photo(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
152 |
+
elif "video" in filemimespotted:
|
153 |
+
viddura = moviepy.editor.VideoFileClip(f"{magapylol}")
|
154 |
+
vidduration = int(viddura.duration)
|
155 |
+
thumbnail_path = f"{alreadylol}/thumbnail.jpg"
|
156 |
+
subprocess.call(['ffmpeg', '-i', magapylol, '-ss', '00:00:10.000', '-vframes', '1', thumbnail_path])
|
157 |
+
safone = await message.reply_video(magapylol, duration=vidduration, thumb=thumbnail_path, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
158 |
+
elif "audio" in filemimespotted:
|
159 |
+
safone = await message.reply_audio(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
160 |
+
else:
|
161 |
+
safone = await message.reply_document(magapylol, progress=progress_for_pyrogram, progress_args=("**Uploading ...** \n", download_msg, start_time), reply_to_message_id=message.message_id)
|
162 |
+
await safone.reply_text(
|
163 |
+
"**Join @url_upload_bots ! \nThanks For Using Me 😘!**",
|
164 |
+
reply_markup=InlineKeyboardMarkup(
|
165 |
+
[
|
166 |
+
[
|
167 |
+
InlineKeyboardButton(
|
168 |
+
"🙌 SHARE 🙌",
|
169 |
+
url="https://t.me/share/url?url=**Hey%20Guys!%20%20Check%20Out%20@imseldrith%20Bots%20Channel.%20%20Share%20His%20Bots%20And%20Support%20Him%20%F0%9F%98%89!%20%20Here%20Is%20The%20Bots%20List%20:-%20https://t.me/url_upload_bots **",
|
170 |
+
)
|
171 |
+
]
|
172 |
+
]
|
173 |
+
),
|
174 |
+
reply_to_message_id=safone.message_id,
|
175 |
+
)
|
176 |
+
await download_msg.delete()
|
177 |
+
await trace_msg.edit(f"#MegaDL: Upload Done! \n\n{user_info}")
|
178 |
+
try:
|
179 |
+
shutil.rmtree(basedir + "/" + userpath)
|
180 |
+
print("[ MegaDL-Bot ] Successfully Cleaned Temp Download Directory!")
|
181 |
+
except Exception as e:
|
182 |
+
print(e)
|
183 |
+
return
|
184 |
+
|
185 |
+
@Client.on_message(filters.command("cancel") & filters.private & filters.incoming & ~filters.edited)
|
186 |
+
async def cancel_dl(bot, message):
|
187 |
+
if Config.UPDATES_CHANNEL:
|
188 |
+
fsub = await handle_force_subscribe(bot, message)
|
189 |
+
if fsub == 400:
|
190 |
+
return
|
191 |
+
userpath = str(message.from_user.id)
|
192 |
+
try:
|
193 |
+
shutil.rmtree(basedir + "/" + userpath)
|
194 |
+
await message.reply_text("✅ **Downloading Canceled Successfully!**", reply_to_message_id=message.message_id)
|
195 |
+
except Exception as e:
|
196 |
+
await print(e)
|
197 |
+
await message.reply_text("❌ **No Active Download Process To Cancel!**", reply_to_message_id=message.message_id)
|
megadl/progress.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# (c) Asm Safone
|
2 |
+
# A Part of MegaDL-Bot <https://github.com/AsmSafone/MegaDL-Bot>
|
3 |
+
|
4 |
+
|
5 |
+
import os
|
6 |
+
import time
|
7 |
+
import math
|
8 |
+
from config import Config
|
9 |
+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
10 |
+
|
11 |
+
|
12 |
+
async def progress_for_pyrogram(
|
13 |
+
current,
|
14 |
+
total,
|
15 |
+
ud_type,
|
16 |
+
message,
|
17 |
+
start
|
18 |
+
):
|
19 |
+
now = time.time()
|
20 |
+
diff = now - start
|
21 |
+
if round(diff % 10.00) == 0 or current == total:
|
22 |
+
# if round(current / total * 100, 0) % 5 == 0:
|
23 |
+
percentage = current * 100 / total
|
24 |
+
speed = current / diff
|
25 |
+
elapsed_time = round(diff) * 1000
|
26 |
+
time_to_completion = round((total - current) / speed) * 1000
|
27 |
+
estimated_total_time = elapsed_time + time_to_completion
|
28 |
+
|
29 |
+
elapsed_time = TimeFormatter(milliseconds=elapsed_time)
|
30 |
+
estimated_total_time = TimeFormatter(milliseconds=estimated_total_time)
|
31 |
+
|
32 |
+
progress = "`[{0}{1}]` \n".format(
|
33 |
+
''.join(["●" for i in range(math.floor(percentage / 5))]),
|
34 |
+
''.join(["○" for i in range(20 - math.floor(percentage / 5))])
|
35 |
+
)
|
36 |
+
|
37 |
+
ok = "`{0}%` \n".format(
|
38 |
+
round(percentage, 2)
|
39 |
+
)
|
40 |
+
|
41 |
+
tmp = ok + progress + "\n➩ **Done:** `{0}` \n➩ **Total:** `{1}` \n➩ **Speed:** `{2}/s` \n➩ **Time Left:** `{3}`".format(
|
42 |
+
humanbytes(current),
|
43 |
+
humanbytes(total),
|
44 |
+
humanbytes(speed),
|
45 |
+
estimated_total_time if estimated_total_time != '' else "0 s"
|
46 |
+
)
|
47 |
+
try:
|
48 |
+
await message.edit(
|
49 |
+
text="**{}** {} \n\n**@imseldtith | @url_upload_bots**".format(
|
50 |
+
ud_type,
|
51 |
+
tmp
|
52 |
+
),
|
53 |
+
reply_markup=InlineKeyboardMarkup(
|
54 |
+
[
|
55 |
+
[
|
56 |
+
InlineKeyboardButton("Cancel Upload", callback_data="cancel_up")
|
57 |
+
]
|
58 |
+
]
|
59 |
+
)
|
60 |
+
)
|
61 |
+
except:
|
62 |
+
pass
|
63 |
+
|
64 |
+
|
65 |
+
def humanbytes(size):
|
66 |
+
# https://stackoverflow.com/a/49361727/4723940
|
67 |
+
# 2**10 = 1024
|
68 |
+
if not size:
|
69 |
+
return ""
|
70 |
+
power = 2**10
|
71 |
+
n = 0
|
72 |
+
Dic_powerN = {0: ' ', 1: 'Ki', 2: 'Mi', 3: 'Gi', 4: 'Ti'}
|
73 |
+
while size > power:
|
74 |
+
size /= power
|
75 |
+
n += 1
|
76 |
+
return str(round(size, 2)) + " " + Dic_powerN[n] + 'B'
|
77 |
+
|
78 |
+
|
79 |
+
def TimeFormatter(milliseconds: int) -> str:
|
80 |
+
seconds, milliseconds = divmod(int(milliseconds), 1000)
|
81 |
+
minutes, seconds = divmod(seconds, 60)
|
82 |
+
hours, minutes = divmod(minutes, 60)
|
83 |
+
days, hours = divmod(hours, 24)
|
84 |
+
tmp = ((str(days) + "d, ") if days else "") + \
|
85 |
+
((str(hours) + "h, ") if hours else "") + \
|
86 |
+
((str(minutes) + "m, ") if minutes else "") + \
|
87 |
+
((str(seconds) + "s, ") if seconds else "") + \
|
88 |
+
((str(milliseconds) + "ms, ") if milliseconds else "")
|
89 |
+
return tmp[:-2]
|