- Added option to block mega folder support
This commit is contained in:
Hafitz Setya 2021-03-10 08:46:46 +07:00 committed by GitHub
parent c07b135e12
commit 1d809560d5
Signed by untrusted user: GitHub
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 21 deletions

View File

@ -82,6 +82,10 @@
"description": "Your password for your mega.nz account.", "description": "Your password for your mega.nz account.",
"required": false "required": false
}, },
"BLOCK_MEGA_FOLDER": {
"description": "If you want to remove mega.nz folder support, set it to True.",
"required": false
},
"BLOCK_MEGA_LINKS": { "BLOCK_MEGA_LINKS": {
"description": "If you want to remove mega.nz mirror support, set it to True.", "description": "If you want to remove mega.nz mirror support, set it to True.",
"required": false "required": false

View File

@ -194,6 +194,14 @@ try:
USE_SERVICE_ACCOUNTS = False USE_SERVICE_ACCOUNTS = False
except KeyError: except KeyError:
USE_SERVICE_ACCOUNTS = False 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: try:
BLOCK_MEGA_LINKS = getConfig('BLOCK_MEGA_LINKS') BLOCK_MEGA_LINKS = getConfig('BLOCK_MEGA_LINKS')
if BLOCK_MEGA_LINKS.lower() == 'true': if BLOCK_MEGA_LINKS.lower() == 'true':

View File

@ -93,19 +93,19 @@ def get_readable_message():
with download_dict_lock: with download_dict_lock:
msg = "" msg = ""
for download in list(download_dict.values()): for download in list(download_dict.values()):
msg += f"<b>Filename :</b> <code>{download.name()}</code>" msg += f"<b>Filename:</b> <code>{download.name()}</code>"
msg += f"\n<b>Status :</b> <i>{download.status()}</i>" msg += f"\n<b>Status:</b> <i>{download.status()}</i>"
if download.status() != MirrorStatus.STATUS_ARCHIVING and download.status() != MirrorStatus.STATUS_EXTRACTING: if download.status() != MirrorStatus.STATUS_ARCHIVING and download.status() != MirrorStatus.STATUS_EXTRACTING:
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code>" msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code>"
if download.status() == MirrorStatus.STATUS_DOWNLOADING: 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: 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()} " msg += f"\n<b>Speed :</b> {download.speed()}, \n<b>ETA:</b> {download.eta()} "
# if hasattr(download, 'is_torrent'): # if hasattr(download, 'is_torrent'):
try: try:
msg += f"\n<b>Info:- Seeders:</b> {download.aria_download().num_seeders}" \ msg += f"\n<b>Seeders:</b> {download.aria_download().num_seeders}" \
f" & <b>Peers :</b> {download.aria_download().connections}" f" | <b>Peers:</b> {download.aria_download().connections}"
except: except:
pass pass
if download.status() == MirrorStatus.STATUS_DOWNLOADING: if download.status() == MirrorStatus.STATUS_DOWNLOADING:

View File

@ -317,7 +317,7 @@ class GoogleDriveHelper:
if meta.get("mimeType") == self.__G_DRIVE_DIR_MIME_TYPE: if meta.get("mimeType") == self.__G_DRIVE_DIR_MIME_TYPE:
dir_id = self.create_directory(meta.get('name'), parent_id) dir_id = self.create_directory(meta.get('name'), parent_id)
result = self.cloneFolder(meta.get('name'), meta.get('name'), meta.get('id'), dir_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) durl = self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)
buttons = button_build.ButtonMaker() buttons = button_build.ButtonMaker()
if SHORTENER is not None and SHORTENER_API is not None: if SHORTENER is not None and SHORTENER_API is not None:
@ -349,7 +349,7 @@ class GoogleDriveHelper:
else: else:
buttons.buildbutton("Drive Link", durl) buttons.buildbutton("Drive Link", durl)
try: 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: except TypeError:
pass pass
if INDEX_URL is not None: if INDEX_URL is not None:

View File

@ -68,9 +68,9 @@ def delete_all_messages():
def update_all_messages(): def update_all_messages():
msg = get_readable_message() msg = get_readable_message()
msg += f"<b>CPU:</b> {psutil.cpu_percent()}%" \ msg += f"<b>CPU:</b> {psutil.cpu_percent()}%\n" \
f" <b>DISK:</b> {psutil.disk_usage('/').percent}%" \ f"<b>RAM:</b> {psutil.virtual_memory().percent}%\n" \
f" <b>RAM:</b> {psutil.virtual_memory().percent}%" f"<b>DISK:</b> {psutil.disk_usage('/').percent}%\n"
with download_dict_lock: with download_dict_lock:
dlspeed_bytes = 0 dlspeed_bytes = 0
uldl_bytes = 0 uldl_bytes = 0
@ -88,7 +88,7 @@ def update_all_messages():
uldl_bytes += float(speedy.split('M')[0]) * 1048576 uldl_bytes += float(speedy.split('M')[0]) * 1048576
dlspeed = get_readable_file_size(dlspeed_bytes) dlspeed = get_readable_file_size(dlspeed_bytes)
ulspeed = get_readable_file_size(uldl_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: with status_reply_dict_lock:
for chat_id in list(status_reply_dict.keys()): for chat_id in list(status_reply_dict.keys()):
if status_reply_dict[chat_id] and msg != status_reply_dict[chat_id].text: if status_reply_dict[chat_id] and msg != status_reply_dict[chat_id].text:
@ -104,9 +104,9 @@ def update_all_messages():
def sendStatusMessage(msg, bot): def sendStatusMessage(msg, bot):
progress = get_readable_message() progress = get_readable_message()
progress += f"<b>CPU:</b> {psutil.cpu_percent()}%" \ progress += f"<b>CPU:</b> {psutil.cpu_percent()}%\n" \
f" <b>DISK:</b> {psutil.disk_usage('/').percent}%" \ f"<b>RAM:</b> {psutil.virtual_memory().percent}%\n" \
f" <b>RAM:</b> {psutil.virtual_memory().percent}%" f"<b>DISK:</b> {psutil.disk_usage('/').percent}%\n"
with download_dict_lock: with download_dict_lock:
dlspeed_bytes = 0 dlspeed_bytes = 0
uldl_bytes = 0 uldl_bytes = 0
@ -124,7 +124,7 @@ def sendStatusMessage(msg, bot):
uldl_bytes += float(speedy.split('M')[0]) * 1048576 uldl_bytes += float(speedy.split('M')[0]) * 1048576
dlspeed = get_readable_file_size(dlspeed_bytes) dlspeed = get_readable_file_size(dlspeed_bytes)
ulspeed = get_readable_file_size(uldl_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: with status_reply_dict_lock:
if msg.message.chat.id in list(status_reply_dict.keys()): if msg.message.chat.id in list(status_reply_dict.keys()):
try: try:

View File

@ -2,10 +2,10 @@ import requests
from telegram.ext import CommandHandler, run_async from telegram.ext import CommandHandler, run_async
from telegram import InlineKeyboardMarkup 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 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 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.ext_utils.exceptions import DirectDownloadLinkException, NotSupportedExtractionArchive
from bot.helper.mirror_utils.download_utils.aria2_download import AriaDownloadHelper from bot.helper.mirror_utils.download_utils.aria2_download import AriaDownloadHelper
from bot.helper.mirror_utils.download_utils.mega_downloader import MegaDownloadHelper from bot.helper.mirror_utils.download_utils.mega_downloader import MegaDownloadHelper
@ -139,7 +139,7 @@ class MirrorListener(listeners.MirrorListeners):
def onUploadComplete(self, link: str, size): def onUploadComplete(self, link: str, size):
with download_dict_lock: 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() buttons = button_build.ButtonMaker()
if SHORTENER is not None and SHORTENER_API is not None: 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 surl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, link)).text
@ -167,7 +167,7 @@ class MirrorListener(listeners.MirrorListeners):
else: else:
uname = f'<a href="tg://user?id={self.message.from_user.id}">{self.message.from_user.first_name}</a>' uname = f'<a href="tg://user?id={self.message.from_user.id}">{self.message.from_user.first_name}</a>'
if uname is not None: if uname is not None:
msg += f'\n\ncc : {uname}' msg += f'\n\ncc: {uname}'
try: try:
fs_utils.clean_download(download_dict[self.uid].path()) fs_utils.clean_download(download_dict[self.uid].path())
except FileNotFoundError: except FileNotFoundError:
@ -238,7 +238,10 @@ def _mirror(bot, update, isTar=False, extract=False):
listener = MirrorListener(bot, update, isTar, tag, extract) listener = MirrorListener(bot, update, isTar, tag, extract)
if bot_utils.is_mega_link(link): 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) 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: else:
mega_dl = MegaDownloadHelper() mega_dl = MegaDownloadHelper()

View File

@ -19,6 +19,7 @@ UPTOBOX_TOKEN = ""
MEGA_API_KEY = "" MEGA_API_KEY = ""
MEGA_EMAIL_ID = "" MEGA_EMAIL_ID = ""
MEGA_PASSWORD = "" MEGA_PASSWORD = ""
BLOCK_MEGA_FOLDER = ""
BLOCK_MEGA_LINKS = "" BLOCK_MEGA_LINKS = ""
STOP_DUPLICATE_MIRROR = "" STOP_DUPLICATE_MIRROR = ""
SHORTENER = "" SHORTENER = ""