Skip to content

Commit

Permalink
v3.9 (breakdowns#19)
Browse files Browse the repository at this point in the history
- Added option to block mega folder support
  • Loading branch information
breakdowns authored Mar 10, 2021
1 parent c07b135 commit 1d80956
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
"description": "Your password for your mega.nz account.",
"required": false
},
"BLOCK_MEGA_FOLDER": {
"description": "If you want to remove mega.nz folder support, set it to True.",
"required": false
},
"BLOCK_MEGA_LINKS": {
"description": "If you want to remove mega.nz mirror support, set it to True.",
"required": false
Expand Down
8 changes: 8 additions & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ def getConfig(name: str):
USE_SERVICE_ACCOUNTS = False
except KeyError:
USE_SERVICE_ACCOUNTS = False
try:
BLOCK_MEGA_FOLDER = getConfig('BLOCK_MEGA_FOLDER')
if BLOCK_MEGA_FOLDER.lower() == 'true':
BLOCK_MEGA_FOLDER = True
else:
BLOCK_MEGA_FOLDER = False
except KeyError:
BLOCK_MEGA_FOLDER = False
try:
BLOCK_MEGA_LINKS = getConfig('BLOCK_MEGA_LINKS')
if BLOCK_MEGA_LINKS.lower() == 'true':
Expand Down
12 changes: 6 additions & 6 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ def get_readable_message():
with download_dict_lock:
msg = ""
for download in list(download_dict.values()):
msg += f"<b>Filename :</b> <code>{download.name()}</code>"
msg += f"\n<b>Status :</b> <i>{download.status()}</i>"
msg += f"<b>Filename:</b> <code>{download.name()}</code>"
msg += f"\n<b>Status:</b> <i>{download.status()}</i>"
if download.status() != MirrorStatus.STATUS_ARCHIVING and download.status() != MirrorStatus.STATUS_EXTRACTING:
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code>"
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
msg += f"\n<b>Downloaded :</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
msg += f"\n<b>Downloaded:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
else:
msg += f"\n<b>Uploaded :</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
msg += f"\n<b>Uploaded:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
msg += f"\n<b>Speed :</b> {download.speed()}, \n<b>ETA:</b> {download.eta()} "
# if hasattr(download, 'is_torrent'):
try:
msg += f"\n<b>Info:- Seeders:</b> {download.aria_download().num_seeders}" \
f" & <b>Peers :</b> {download.aria_download().connections}"
msg += f"\n<b>Seeders:</b> {download.aria_download().num_seeders}" \
f" | <b>Peers:</b> {download.aria_download().connections}"
except:
pass
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_utils/upload_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def clone(self, link):
if meta.get("mimeType") == self.__G_DRIVE_DIR_MIME_TYPE:
dir_id = self.create_directory(meta.get('name'), parent_id)
result = self.cloneFolder(meta.get('name'), meta.get('name'), meta.get('id'), dir_id)
msg += f'<b>Filename : </b><code>{meta.get("name")}</code>\n<b>Size : </b>{get_readable_file_size(self.transferred_size)}'
msg += f'<b>Filename: </b><code>{meta.get("name")}</code>\n<b>Size: </b>{get_readable_file_size(self.transferred_size)}'
durl = self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)
buttons = button_build.ButtonMaker()
if SHORTENER is not None and SHORTENER_API is not None:
Expand Down Expand Up @@ -349,7 +349,7 @@ def clone(self, link):
else:
buttons.buildbutton("Drive Link", durl)
try:
msg += f'\n<b>Size : </b><code>{get_readable_file_size(int(meta.get("size")))}</code>'
msg += f'\n<b>Size: </b><code>{get_readable_file_size(int(meta.get("size")))}</code>'
except TypeError:
pass
if INDEX_URL is not None:
Expand Down
16 changes: 8 additions & 8 deletions bot/helper/telegram_helper/message_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def delete_all_messages():

def update_all_messages():
msg = get_readable_message()
msg += f"<b>CPU:</b> {psutil.cpu_percent()}%" \
f" <b>DISK:</b> {psutil.disk_usage('/').percent}%" \
f" <b>RAM:</b> {psutil.virtual_memory().percent}%"
msg += f"<b>CPU:</b> {psutil.cpu_percent()}%\n" \
f"<b>RAM:</b> {psutil.virtual_memory().percent}%\n" \
f"<b>DISK:</b> {psutil.disk_usage('/').percent}%\n"
with download_dict_lock:
dlspeed_bytes = 0
uldl_bytes = 0
Expand All @@ -88,7 +88,7 @@ def update_all_messages():
uldl_bytes += float(speedy.split('M')[0]) * 1048576
dlspeed = get_readable_file_size(dlspeed_bytes)
ulspeed = get_readable_file_size(uldl_bytes)
msg += f"\n<b>DL:</b> {dlspeed}ps 🔻| <b>UL:</b> {ulspeed}ps 🔺\n"
msg += f"\n<b>DL:</b> {dlspeed}ps | <b>UL:</b> {ulspeed}ps \n"
with status_reply_dict_lock:
for chat_id in list(status_reply_dict.keys()):
if status_reply_dict[chat_id] and msg != status_reply_dict[chat_id].text:
Expand All @@ -104,9 +104,9 @@ def update_all_messages():

def sendStatusMessage(msg, bot):
progress = get_readable_message()
progress += f"<b>CPU:</b> {psutil.cpu_percent()}%" \
f" <b>DISK:</b> {psutil.disk_usage('/').percent}%" \
f" <b>RAM:</b> {psutil.virtual_memory().percent}%"
progress += f"<b>CPU:</b> {psutil.cpu_percent()}%\n" \
f"<b>RAM:</b> {psutil.virtual_memory().percent}%\n" \
f"<b>DISK:</b> {psutil.disk_usage('/').percent}%\n"
with download_dict_lock:
dlspeed_bytes = 0
uldl_bytes = 0
Expand All @@ -124,7 +124,7 @@ def sendStatusMessage(msg, bot):
uldl_bytes += float(speedy.split('M')[0]) * 1048576
dlspeed = get_readable_file_size(dlspeed_bytes)
ulspeed = get_readable_file_size(uldl_bytes)
progress += f"\n<b>DL:</b>{dlspeed}ps 🔻| <b>UL:</b>{ulspeed}ps 🔺\n"
progress += f"\n<b>DL: </b>{dlspeed}ps | <b>UL: </b>{ulspeed}ps \n"
with status_reply_dict_lock:
if msg.message.chat.id in list(status_reply_dict.keys()):
try:
Expand Down
13 changes: 8 additions & 5 deletions bot/modules/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from telegram.ext import CommandHandler, run_async
from telegram import InlineKeyboardMarkup

from bot import Interval, INDEX_URL, BUTTON_THREE_NAME, BUTTON_THREE_URL, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, BLOCK_MEGA_LINKS
from bot import Interval, INDEX_URL, BUTTON_THREE_NAME, BUTTON_THREE_URL, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, BLOCK_MEGA_LINKS, BLOCK_MEGA_FOLDER
from bot import dispatcher, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_dict, download_dict_lock, SHORTENER, SHORTENER_API
from bot.helper.ext_utils import fs_utils, bot_utils
from bot.helper.ext_utils.bot_utils import setInterval
from bot.helper.ext_utils.bot_utils import setInterval, get_mega_link_type
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException, NotSupportedExtractionArchive
from bot.helper.mirror_utils.download_utils.aria2_download import AriaDownloadHelper
from bot.helper.mirror_utils.download_utils.mega_downloader import MegaDownloadHelper
Expand Down Expand Up @@ -139,7 +139,7 @@ def onUploadProgress(self):

def onUploadComplete(self, link: str, size):
with download_dict_lock:
msg = f'<b>Filename : </b><code>{download_dict[self.uid].name()}</code>\n<b>Size : </b><code>{size}</code>'
msg = f'<b>Filename: </b><code>{download_dict[self.uid].name()}</code>\n<b>Size: </b><code>{size}</code>'
buttons = button_build.ButtonMaker()
if SHORTENER is not None and SHORTENER_API is not None:
surl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, link)).text
Expand Down Expand Up @@ -167,7 +167,7 @@ def onUploadComplete(self, link: str, size):
else:
uname = f'<a href="tg://user?id={self.message.from_user.id}">{self.message.from_user.first_name}</a>'
if uname is not None:
msg += f'\n\ncc : {uname}'
msg += f'\n\ncc: {uname}'
try:
fs_utils.clean_download(download_dict[self.uid].path())
except FileNotFoundError:
Expand Down Expand Up @@ -238,7 +238,10 @@ def _mirror(bot, update, isTar=False, extract=False):

listener = MirrorListener(bot, update, isTar, tag, extract)
if bot_utils.is_mega_link(link):
if BLOCK_MEGA_LINKS:
link_type = get_mega_link_type(link)
if link_type == "folder" and BLOCK_MEGA_FOLDER:
sendMessage("Mega folder are blocked!", bot, update)
elif BLOCK_MEGA_LINKS:
sendMessage("Mega links are blocked bcoz mega downloading is too much unstable and buggy. mega support will be added back after fix", bot, update)
else:
mega_dl = MegaDownloadHelper()
Expand Down
1 change: 1 addition & 0 deletions config_sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ UPTOBOX_TOKEN = ""
MEGA_API_KEY = ""
MEGA_EMAIL_ID = ""
MEGA_PASSWORD = ""
BLOCK_MEGA_FOLDER = ""
BLOCK_MEGA_LINKS = ""
STOP_DUPLICATE_MIRROR = ""
SHORTENER = ""
Expand Down

0 comments on commit 1d80956

Please sign in to comment.