stop duplicate mega and mega limit (#151)
* stop duplicate mega and mega limit * fix msg not deleted
This commit is contained in:
parent
23ffce598e
commit
e41d443c0c
|
|
@ -187,6 +187,12 @@ try:
|
|||
CLONE_LIMIT = None
|
||||
except KeyError:
|
||||
CLONE_LIMIT = None
|
||||
try:
|
||||
MEGA_LIMIT = getConfig('MEGA_LIMIT')
|
||||
if len(MEGA_LIMIT) == 0:
|
||||
MEGA_LIMIT = None
|
||||
except KeyError:
|
||||
MEGA_LIMIT = None
|
||||
try:
|
||||
BUTTON_FOUR_NAME = getConfig('BUTTON_FOUR_NAME')
|
||||
BUTTON_FOUR_URL = getConfig('BUTTON_FOUR_URL')
|
||||
|
|
@ -219,6 +225,14 @@ try:
|
|||
STOP_DUPLICATE_MIRROR = False
|
||||
except KeyError:
|
||||
STOP_DUPLICATE_MIRROR = False
|
||||
try:
|
||||
STOP_DUPLICATE_MEGA = getConfig('STOP_DUPLICATE_MEGA')
|
||||
if STOP_DUPLICATE_MEGA.lower() == 'true':
|
||||
STOP_DUPLICATE_MEGA = True
|
||||
else:
|
||||
STOP_DUPLICATE_MEGA = False
|
||||
except KeyError:
|
||||
STOP_DUPLICATE_MEGA = False
|
||||
try:
|
||||
VIEW_LINK = getConfig('VIEW_LINK')
|
||||
if VIEW_LINK.lower() == 'true':
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
from bot import LOGGER, MEGA_API_KEY, download_dict_lock, download_dict, MEGA_EMAIL_ID, MEGA_PASSWORD
|
||||
import threading
|
||||
from mega import (MegaApi, MegaListener, MegaRequest, MegaTransfer, MegaError)
|
||||
from bot.helper.telegram_helper.message_utils import update_all_messages
|
||||
from bot.helper.telegram_helper.message_utils import update_all_messages, sendMarkup, deleteMessage, sendMessage
|
||||
import os
|
||||
from bot.helper.ext_utils.bot_utils import new_thread, get_mega_link_type
|
||||
from bot.helper.ext_utils.bot_utils import new_thread, get_mega_link_type, get_readable_file_size
|
||||
from bot.helper.mirror_utils.status_utils.mega_download_status import MegaDownloadStatus
|
||||
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
|
||||
from bot import MEGA_LIMIT, STOP_DUPLICATE_MEGA
|
||||
import random
|
||||
import string
|
||||
|
||||
|
|
@ -151,9 +153,6 @@ class MegaDownloadHelper:
|
|||
global listeners
|
||||
mega_listener = MegaAppListener(executor.continue_event, listener)
|
||||
listeners.append(mega_listener)
|
||||
with download_dict_lock:
|
||||
download_dict[listener.uid] = MegaDownloadStatus(mega_listener, listener)
|
||||
os.makedirs(path)
|
||||
api.addListener(mega_listener)
|
||||
if MEGA_EMAIL_ID is not None and MEGA_PASSWORD is not None:
|
||||
executor.do(api.login, (MEGA_EMAIL_ID, MEGA_PASSWORD))
|
||||
|
|
@ -167,7 +166,46 @@ class MegaDownloadHelper:
|
|||
folder_api.addListener(mega_listener)
|
||||
executor.do(folder_api.loginToFolder, (mega_link,))
|
||||
node = folder_api.authorizeNode(mega_listener.node)
|
||||
|
||||
if STOP_DUPLICATE_MEGA:
|
||||
msg = sendMessage('Check the File/Folder if already in drive...', listener.bot, listener.update)
|
||||
mname = node.getName()
|
||||
if listener.isTar == True:
|
||||
mname = mname + ".tar"
|
||||
if listener.extract == True:
|
||||
smsg = None
|
||||
else:
|
||||
gd = GoogleDriveHelper()
|
||||
smsg, button = gd.drive_list(mname)
|
||||
if smsg:
|
||||
deleteMessage(listener.bot, msg)
|
||||
msg1 = "File/Folder is already available in Drive.\nHere are the search results:"
|
||||
sendMarkup(msg1, listener.bot, listener.update, button)
|
||||
return
|
||||
else:
|
||||
deleteMessage(listener.bot, msg)
|
||||
if MEGA_LIMIT is not None:
|
||||
msg2 = sendMessage('Check the File/Folder size...', listener.bot, listener.update)
|
||||
limit = MEGA_LIMIT
|
||||
limit = limit.split(' ', maxsplit=1)
|
||||
limitint = int(limit[0])
|
||||
msg3 = f'Failed, Clone limit is {MEGA_LIMIT}.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.'
|
||||
if 'GB' in limit or 'gb' in limit:
|
||||
if api.getSize(node) > limitint * 1024**3:
|
||||
deleteMessage(listener.bot, msg2)
|
||||
sendMessage(msg3, listener.bot, listener.update)
|
||||
return
|
||||
else:
|
||||
deleteMessage(listener.bot, msg2)
|
||||
elif 'TB' in limit or 'tb' in limit:
|
||||
if api.getSize(node) > limitint * 1024**4:
|
||||
deleteMessage(listener.bot, msg2)
|
||||
sendMessage(msg3, listener.bot, listener.update)
|
||||
return
|
||||
else:
|
||||
deleteMessage(listener.bot, msg2)
|
||||
with download_dict_lock:
|
||||
download_dict[listener.uid] = MegaDownloadStatus(mega_listener, listener)
|
||||
os.makedirs(path)
|
||||
gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=8))
|
||||
mega_listener.setValues(node.getName(), api.getSize(node), gid)
|
||||
executor.do(api.startDownload,(node,path))
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ def cloneNode(update, context):
|
|||
msg3 = "<b>File/Folder is already available in Drive</b>.\n<b>Here are the search results:</b>"
|
||||
sendMarkup(msg3, context.bot, update, button)
|
||||
return
|
||||
else:
|
||||
if CLONE_LIMIT is None:
|
||||
deleteMessage(context.bot, msg1)
|
||||
if CLONE_LIMIT is not None:
|
||||
limit = CLONE_LIMIT
|
||||
limit = limit.split(' ', maxsplit=1)
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@ MEGA_PASSWORD = ""
|
|||
BLOCK_MEGA_FOLDER = ""
|
||||
BLOCK_MEGA_LINKS = ""
|
||||
STOP_DUPLICATE_MIRROR = ""
|
||||
STOP_DUPLICATE_MEGA = ""
|
||||
STOP_DUPLICATE_CLONE = ""
|
||||
SHORTENER = ""
|
||||
SHORTENER_API = ""
|
||||
CLONE_LIMIT = "" #leave space between number and unit (TB or GB only)
|
||||
MEGA_LIMIT = ""
|
||||
IMAGE_URL = "https://telegra.ph/file/db03910496f06094f1f7a.jpg"
|
||||
# Change ENABLE_FILESIZE_LIMIT = True if you want to use MAX_TORRENT_SIZE
|
||||
ENABLE_FILESIZE_LIMIT = false
|
||||
|
|
|
|||
Loading…
Reference in New Issue